## Summary

To test the difference between two values, and return a message when the difference is less or greater than a target percentage you can use a formula based on the IF function and the ABS function. In the example shown, the formula in E5, copied down, is:

``````=IF(ABS(D5)<=target,"Yes","No")
``````

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%.

## Generic formula

``=IF(ABS(percentage)<=target,"Yes","No")``

## Explanation

In this example, the goal to calculate the difference as a percentage between two values then check the result to see if its within a given target percentage. The values come from the Expected and Actual columns in the worksheet. The challenge is that the difference might be negative or positive, and we need to cater to both.

### Difference as percentage

To calculate the difference as a percentage, we can use a general formula like this:

``````=(actual-expected)/expected
``````

After converting this to cell references, we have:

``````=(C5-B5)/B5
``````

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:

``````=IF(ABS(D5)<=target,"Yes","No")
``````

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:

``````=IF(ABS((C5-B5)/B5)<=target,"Yes","No")
``````

The result is the same, but this version does not need to use column D as a helper column.

Author

### 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.