IF - Choose between two outcomes
Turn a comparison into an action label or calculation, with clear handling of the boundary between the two outcomes.
By the end, you can
- Write a logical test and two results.
- Include or exclude threshold values deliberately.
- Return text or numeric calculations from IF.
Before you start: Read cell references and simple comparisons such as B2<20.
In this lesson
One question, two possible results
IF tests a condition and chooses one result when it is TRUE and another when it is FALSE. HR can label an attendance shortfall, finance can flag an overdue balance, and operations can decide whether stock needs replenishment. State the policy in plain language before translating it into a formula.
Syntax and arguments
=IF(logical_test, value_if_true, [value_if_false])The results can be quoted text, numbers, cell references, or calculations. Supplying both outcomes makes a report explicit.
| Argument | Purpose | Example |
|---|---|---|
logical_testRequired | A condition that evaluates to TRUE or FALSE. | B2<20 |
value_if_trueRequired | The result when the test passes. | "Review" |
value_if_falseOptional | The result when the test fails; explicitly set this in reports. | "OK" |
Flag attendance below 20 days
OK| A | B | C | |
|---|---|---|---|
| 1 | Employee | Days | Decision |
| 2 | Anika | 22 | OK |
| 3 | Dev | 18 | Review |
| 4 | Meera | 20 | OK |
| 5 | Rahul | 19 | Review |
=IF(B2<20,"Review","OK")22<20 is FALSE, so Anika gets OK. The references move to B3, B4, and B5 when filled.
Text decisions and numeric results
=IF(B3<20,"Review","OK")Dev has 18 days, so the test is TRUE.
=IF(B2>=20,500,0)For a policy awarding ₹500 when attendance reaches 20 days, Anika qualifies. Numeric outputs are not quoted.
=IF(B3<20,20-B3,0)Return a calculation in the TRUE branch: Dev is two days short.
Comparisons, text, and missing inputs
- Use = for equality, <> for not equal, and >= or <= for inclusive boundaries. These comparison operators go inside the logical test.
- Quote literal labels, but not cell addresses or numeric calculations. B2 is a reference; "B2" is text.
- If value_if_false is omitted, a failed test returns FALSE. That is usually less useful than an explicit report label.
- Errors in the test are not automatically handled by IF. Blank numeric inputs can compare like zero, so validate missing data before making a business decision.
Common mistakes and fixes
Check your understanding
Choose an answer for instant feedback. You can try again; answers stay only on this page.