where target is the named range G5. In cell E5, the result is “Yes”, because the difference in D5 is less than or equal to 5%.
Difference as percentage
To calculate the difference as a percentage, we can use a general formula like this: After converting this to cell references, we have: As the formula is copied down, it returns a percentage difference in each row. Note that some values are negative. Note: the results are decimal values like 0.05 and they must be formatted with the percentage number format to display as 5%, 7%, etc.
Compare to target
To compare the percentages to the target percentage, we use the IF function like this in cell E5: where target is the named range G5. This formula uses the ABS function to convert the percentages in column D to positive numbers. Then it uses the IF function to compare the result from ABS to the target (set to 5% in the example shown). If the logical test returns TRUE, the difference is within 5% and IF returns “Yes”. Otherwise, IF returns “No”. Notice both results are text values wrapped in double quotes (""). As the formula is copied down, we get a new result in each row. If the value in G5 is changed to a new percentage, all results recalculate.
All-in-one-formula
In the example shown, column D is used to calculate the difference as a percentage, in order to make the example easier to understand. However, you can combine both formulas above into a single formula like this if needed: The result is the same, but this version does not need to use column D as a helper column.
Dave Bruns
Hi - I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.