What is the IF function?
=IF(logical_test, value_if_true, [value_if_false])IF checks a condition and returns one value when it is TRUE and another when it is FALSE. It is the basic building block for pass/fail labels, bonuses, flags and status columns.
The condition is usually a comparison such as B2>=60. Text results must be in double quotes, like "Pass".
Arguments
- logical_test
- A comparison that is either TRUE or FALSE, such as B2>=60 or A2="Seoul".
- value_if_true
- What to return when the test is TRUE. It can be a number, text in quotes, or another formula.
- value_if_false
- What to return when the test is FALSE. If omitted, IF returns FALSE.
IF examples
Example 1. Pass or fail
=IF(B2>=60, "Pass", "Fail")B2 is 85, which is 60 or more, so the result is Pass.
Example 2. Leave a blank instead
=IF(B2>=90, "Top", "")Two double quotes with nothing between them return empty text, so only top scores are labeled.
Example 3. More than two outcomes
=IF(B2>=90, "A", IF(B2>=80, "B", "C"))An IF inside another IF checks the next condition only when the first is FALSE. For many bands, IFS or a lookup table is easier to read.
Common mistakes
Text without quotes
IF(B2>=60, Pass, Fail) returns #NAME? because Excel treats Pass as a name. Write "Pass".
Numbers in quotes
"60" is text. Comparing B2>="60" doesn't compare numbers. Write 60 without quotes.
Order of nested conditions
With nested IFs, check the strictest condition first. If B2>=60 comes before B2>=90, a 95 stops at the first test.
FAQ
- How do I check two conditions at once?
- Use AND or OR inside the test, for example IF(AND(B2>=60, C2>=60), "Pass", "Fail").
- What does IF return if value_if_false is left out?
- It returns FALSE when the test is FALSE.