Refers to Excel function which helps evaluating logical conditions and decisions. IF checks if given criteria passes the test the return one value i.e. true or false. In this article we will cover IF, Nested IF (IF within IF) with AND, OR and NOT logical functions.
=IF(logical_test, [value_if_true], [value_if_false)
- logical_test: refers to condition which should be evaluated
- value_if_true: if logical_test passed the this parameter would be returned as value as part of the result
- value_if_false: if logical_test fails, this parameter would be returned as value as part of the result
Consider you want to check if in given cell the value is identical to the value you are passing will result as “Match Found” else “Not Matched”. Refer below data source where we are performing match for a product “Car”:
Nested IF example
IF within IF, suppose we want to make a decision based on two conditions where Product equal to Car and Bus then result should be “Acceptable” else “Not Acceptable“. This type of condition can be evaluated using nested if as shown below:
Note: in above example I have not given the false case for first IF condition because I wanted to test next IF only when first IF is true. If you change condition for first IF then result would be evaluated to false.
IF with AND
AND is a logical function which returns TRUE or FALSE, If given all conditions are TRUE the it will return True, If anyone of the condition sets to False then AND returns False as result. If we want to evaluate multiple conditions with IF statement the AND function is very useful. Consider below formula where we are performing IF with AND function and returning “Valid”, “Invalid” as result:
IF with OR
OR is a logical function which returns True or False similar to AND but the logical evaluation is different of OR than AND. OR returns True if at least one of the conditions returns True, If all conditions are false then it will return False.
IF with NOT
NOT is a logical function which returns True, False based on condition evaluated to as shown below:
Conclusion: it is not necessary that we should use only one logical function (AND, OR, NOT) with IF, user can use any of them and repeatedly as well.