Logical
IF function playground
Returns one value if a condition is TRUE and another if it is FALSE.
The playground runs in your browser. Nothing you type is sent anywhere.
How IF works
IF works out the test first. If it is TRUE, IF returns the second argument; if FALSE, the third. The branch that isn't chosen is never calculated.
Text results go in double quotes. Use "" to show nothing. To test more than two outcomes, use IFS or put another IF inside.
Syntax
=IF(logical_test, [value_if_true], [value_if_false])| Argument | What it means |
|---|---|
logical_testrequired | A comparison or anything that gives TRUE or FALSE, such as B2>=70. |
value_if_trueoptional | What to return when the test is TRUE. |
value_if_falseoptional | What to return when the test is FALSE. |
Examples
| Formula | What it does | Result |
|---|---|---|
=IF(B2>=70,"Pass","Fail") | Pass or fail on Test 1, for every student. | Pass · Fail · Pass · Fail … |
=IF(D2<0.8,"Check attendance","OK") | Flag attendance below 80%. | OK · OK · OK · Check attendance … |
=IF(B2>C2,"Test 1","Test 2") | Which test was better. | Test 1 · Test 2 · Test 2 · Test 2 … |
=IF(AVERAGE(B2:C2)>=85,"Honor roll","") | Show text only when the average is 85 or more. | Honor roll · "" · "" · "" … |
Common mistakes
Text without quotesPass must be written "Pass". Without quotes Excel looks for a name and shows #NAME?.
Too many nested IFsSeveral IFs inside each other are hard to read. IFS or a lookup table is usually clearer.
Related functions
Learn more
Download the example workbook (.xlsx)
The workbook has the same sample data and formulas, plus a practice sheet.