Explanation
In this example the goal is to check if values in column B are within a tolerance of .005. If a value is within tolerance, the formula should return “OK”. If the value is out of tolerance, the formula should return “Fail”. The expected value is listed in column C, and the allowed tolerance is listed in column D. The solution is based on the IF function together with the ABS function.
Core logic
To check if a value is within a given tolerance, we can use a simple logical test like this:
=ABS(actual-expected)<=tolerance // logical test
Inside the ABS function, the actual value is subtracted from the expected value. The result may be positive or negative, depending on the actual value, so the ABS function is used to convert the result to a positive number: negative values become positive and positive values are unchanged. The result from ABS is compared to the allowed tolerance with the logical operator less than or equal (<=). The expression returns TRUE when a value is less than or equal to the allowed tolerance, and FALSE if not.
IF function
To complete the solution, we need to place the generic logical expression above into the IF function and providing values for a TRUE and FALSE result. The first step is to revise the generic expression above to use worksheet references:
ABS(B5-C5)<=D5 // logical test
Then, we drop the expression into the IF function as the logical_test argument :
=IF(ABS(B5-C5)<=D5,"OK","Fail") // final formula
When the logical test returns TRUE, IF returns “OK”. When the logical test returns FALSE, IF returns “Fail”. These messages can be customized as needed.
List all values within tolerance
The basic concept explained above can be extended to list values within tolerance or out of tolerance with the FILTER function .
Explanation
In this example, the goal create a formula that will return TRUE when a volunteer has successfully logged the required number of hours in each of the three categories. Two requirements must be satisfied:
- A volunteer should have at least 5 hours in each of the three categories.
- A volunteer needs to have at least 15 hours in total.
Both requirements are evaluated inside a single AND function in a formula like this:
=AND(COUNTIF(C6:E6,">=5")=3,SUM(C6:E6)>=15)
The first requirement is at least 5 volunteer hours in each of the 3 categories: A, B, and C. This requirement is tested with a logical statement based on the COUNTIF function :
COUNTIF(C6:E6,">=5")=3
In the range C6:E6, we count numbers greater than or equal to 5. We need a result of 3 for this requirement to be satisfied, so we compare the result from COUNTIF to 3 directly. The result will be TRUE or FALSE.
The second requirement is to have at least 15 volunteer hours in total. This requirement is tested with a simple logical expression based on the SUM function :
SUM(C6:E6)>=15)
Here, we use SUM to add up all ours in the range C6:C15 then we compare the result to the number 15 with the greater than or equal to operator (>=). As long as the sum is at least 15, this expression will return TRUE.
Finally the results from the two expressions above are evaluated by the AND function. If both the logical expressions return TRUE, the AND function will return TRUE. If either expression returns FALSE, AND will return FALSE.