Excel IF Function
The IF function lets a cell display one value when a condition is true and a different value when it is false, forming the basis of decision-making in Excel formulas.
The Structure of IF
IF takes three arguments: IF(logical_test, value_if_true, value_if_false). The logical_test is any expression that evaluates to TRUE or FALSE, such as a comparison between a cell and a number. Excel returns the second argument when the test is true and the third argument when it is false.
Example
=IF(A1>50,"Pass","Fail")Comparison Operators Used in Logical Tests
Nesting IF for More Than Two Outcomes
A single IF only chooses between two results. To handle several possible outcomes, such as assigning a letter grade, place another IF inside the value_if_false argument. Excel checks each condition in order and stops at the first one that is true.
Example
=IF(A1>=90,"A",IF(A1>=80,"B",IF(A1>=70,"C","F")))Combining IF with AND and OR
The logical_test argument can itself be an AND or OR function when a decision depends on more than one condition. AND requires every condition to be true, while OR only needs one of them to be true.
- =IF(AND(A1>=60,B1="Yes"),"Eligible","Not Eligible") requires both conditions to hold.
- =IF(OR(A1="Manager",A1="Director"),"Approved","Needs Review") passes if either title matches.
- Conditions can mix text comparisons, numeric comparisons, and even other functions.