The IF function in Excel
IF checks a condition and returns one result when it's true and another when it's false. It's how you turn data into decisions: flag overspending, label orders as late, or calculate a bonus only for people who hit target. Almost every Excel test includes at least one IF question.
Syntax
=IF(logical_test, [value_if_true], [value_if_false])
| logical_test | A comparison that is either TRUE or FALSE, like C2>B2 or A2="Paid". |
|---|---|
| value_if_true | Optional, but almost always given. What to return when the test is TRUE: text in quotes, a number, or another formula. |
| value_if_false | Optional. What to return when the test is FALSE. If left out, IF returns FALSE. |
Try it yourself
This is a live spreadsheet. Type the formula and press Enter.
In E2, use IF to show "Reorder" when the stock in C2 is at or below the reorder level in D2, and "OK" otherwise.
| A | B | C | D | E | F | G | |
|---|---|---|---|---|---|---|---|
| 1 | Action | ||||||
| 2 | |||||||
| 3 | |||||||
| 4 | |||||||
| 5 | |||||||
| 6 | |||||||
| 7 | |||||||
| 8 | |||||||
| 9 |
Tip: "At or below" means less than or equal to. Both results are text, so they need quotes.
Examples
=IF(C2>B2,"Over budget","Within budget")→ "Over budget"Compares Marketing's actual spend with its budget and returns a label for either case.
=IF(C3<B3,B3-C3,0)→ 1800Returns a calculation instead of text: the money IT has left, or 0 if it has none.
=IF(C5>B5*1.1,"Review","")→ "Review"Flags Facilities only if it overspent by more than 10%. The empty quotes "" leave the cell looking blank otherwise.
Example data
| 1 | Department | Budget | Actual |
|---|---|---|---|
| 2 | Marketing | 12000 | 13450 |
| 3 | IT | 18000 | 16200 |
| 4 | HR | 6500 | 6480 |
| 5 | Facilities | 9000 | 10150 |
Common mistakes
Text without quotes
=IF(C2>B2,Over,OK)returns #NAME? because Excel reads Over and OK as names. Put text results in double quotes:"Over".Numbers in quotes
C2>"100"compares against the text "100", not the number. Leave numbers unquoted:C2>100.Wrong boundary
>and>=give different answers for a value exactly on the line. Read the rule carefully: "at least 50" means>=50.Too many nested IFs
Three or more IFs inside each other get hard to read and easy to break. Use IFS for several bands, or a lookup table with XLOOKUP.
FAQ
How do I use IF with two conditions?+
Put AND or OR inside the test. =IF(AND(B2>=100,C2="Yes"),"Bonus","") needs both to be true; OR needs only one.
How do I make IF return a blank cell?+
Use two double quotes as the result: =IF(A2="","",A2*2). The cell looks empty, though it technically contains empty text.
Can IF return a calculation?+
Yes. Either result can be any formula, such as =IF(C2>B2,C2-B2,0) to show only the overspend.
Lesson
Master IF step by step: The IF function
Make a cell show one result or another depending on a condition, like Pass/Fail or Over/Under budget.