Skip to content

IF

Tests a condition and returns one value if it is true and another if it is false. It is the building block of most decision logic in a workbook.

Syntax

=IF(, , )

Logical

Every version of Excel, including Microsoft 365, Excel 2024, 2021, 2019, 2016 and earlier, Excel for the web and the mobile apps.

Try it

Edit the formula in C2 or change the inputs. The sheet recalculates as you type.

C2
A
B
C
D
1
Rep
Sales
Bonus?
2
R-01
62,000
Bonus
3
R-02
41,500
4
R-03
50,000
5
6

C2 =IF(B2>=50000,"Bonus","No bonus") returns Bonus

How IF works

IF checks a condition and returns one result when it is true and another when it is false. =IF(B2>=50000, "Bonus", "No bonus") shows "Bonus" when B2 is at least 50,000 and "No bonus" otherwise. It is the most used function after SUM, and nearly every model uses it somewhere.

The three arguments

  • logical_test is a comparison such as B2>=50000, A2="Paid" or C2<>"", or any formula that returns TRUE or FALSE. A number is true unless it is zero.
  • value_if_true is returned when the test is true.
  • value_if_false is returned when the test is false. If you leave it out completely, a false test returns the word FALSE in the cell, which usually isn't what you want. Always give the third argument, even when it is "" for "show nothing".

Text must be in double quotes. Numbers and cell references aren't. The comparison is not case-sensitive, so A2="paid" is true for "Paid".

Combining tests

AND and OR let one IF test several conditions: =IF(AND(B2>=18, C2="Yes"), "Eligible", "Not eligible"). For more than two outcomes, you can nest IFs inside each other: =IF(B2>=85,"A",IF(B2>=70,"B","C")). Excel allows 64 levels, but anything past three becomes hard to read and easy to get wrong.

When to use something other than nested IF

  • IFS lists the tests in order without nesting, and is clearer for several ranges.
  • SWITCH compares one value with a list of exact matches, which suits codes such as "N", "S", "E" and "W".
  • A lookup table, read with XLOOKUP or VLOOKUP, is better when the bands change often. You edit a table instead of a formula, and every formula that reads it stays correct.

Handling blanks and errors

An empty cell counts as zero in a number comparison and as empty text in a text comparison, so =IF(A2="", "", A2*2) is the usual way to leave a result blank when its input is blank. If the logical_test itself returns an error, IF returns that error. Wrap the calculation in IFERROR or IFNA to control it.

Things to avoid

Don't repeat the same calculation in both branches when only part of it changes. Move the common part out of the IF. And don't type constants such as tax rates or thresholds into the formula. Put them in cells and reference them, so a change is made once.

IF only evaluates the branch it needs, so it can protect a formula that would otherwise error: =IF(C2=0, 0, B2/C2) never divides when C2 is zero.

Arguments

logical_test
The condition to check, such as B2>=50000 or A2="Paid". Anything that evaluates to TRUE or FALSE works. A number counts as true if it isn't zero. Text other than "TRUE" and "FALSE" returns #VALUE!.
value_if_trueoptional
What to return when the test is true. It can be text in quotes, a number, a reference or another formula. If you leave the argument empty, as in IF(A1>0,,"No"), the result is 0.
value_if_falseoptional
What to return when the test is false. If you leave out the argument and the comma, a false test returns FALSE. If you include the comma but nothing after it, the result is 0.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Return text depending on a number

C2 =IF(B2>=50000,"Bonus","No bonus")

Result: Bonus

B2 is 62,000, which is at least 50,000, so IF returns "Bonus". R-03 sits exactly on 50,000 and also qualifies, because the test uses >=.

C2
A
B
C
D
1
Rep
Sales
Bonus?
2
R-01
62,000
Bonus
3
R-02
41,500
4
R-03
50,000
5
6

C2 =IF(B2>=50000,"Bonus","No bonus") returns Bonus

Example 2

Return a calculation in one branch

D2 =IF(C2>30,B2*0.02,0)

Result: 25

C2 is 45 days, which is more than 30, so the fee is 2% of 1,250. For INV-2 the test is false and the fee is 0.

D2
A
B
C
D
1
Invoice
Amount
Days overdue
Late fee
2
INV-1
1250
45
25
3
INV-2
980
12
4
5
6

D2 =IF(C2>30,B2*0.02,0) returns 25

Example 3

Avoid a #DIV/0! error

D2 =IF(C2=0,0,B2/C2)

Result: 0

North has no orders, so dividing would give #DIV/0!. The test catches the zero first, and IF returns 0 without evaluating the division.

D2
A
B
C
D
1
Region
Revenue
Orders
Revenue per order
2
North
48200
0
0
3
South
31750
125
4
5

D2 =IF(C2=0,0,B2/C2) returns 0

Example 4

Leave a cell blank when the input is blank

D3 =IF(B3="","",B3*C3)

Result:

B3 is empty, so the test is true and IF returns empty text instead of 0. Filled down the column, rows without a quantity stay blank.

D3
A
B
C
D
1
Item
Qty
Unit price
Line total
2
Gloves
12
8.95
3
Tape
4
5
6

D3 =IF(B3="","",B3*C3) returns

Example 5

Nested IF for three outcomes

C2 =IF(B2>=85,"A",IF(B2>=70,"B","C"))

Result: B

The first test fails (72 is below 85), so IF moves to the inner IF. 72 is at least 70, so the result is B. Put the highest threshold first.

C2
A
B
C
D
1
Student
Score
Grade
2
S-1
72
B
3
4
5

C2 =IF(B2>=85,"A",IF(B2>=70,"B","C")) returns B

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In D2, show Chase when the invoice is more than 30 days overdue and OK otherwise. Fill down to D7.

Answer in D2, then it fills down to D7.

D2
A
B
C
D
E
F
1
Invoice
Amount
Days overdue
Action
Late fee
2
INV-1
1,250
12
3
INV-2
980
45
4
INV-3
2,175
30
5
INV-4
640
0
6
INV-5
1,890
61
7
INV-6
320
18
8

Common mistakes

  • Forgetting the third argument means a false test shows the word FALSE in the cell. Give it explicitly, even as "".
  • Text results and text comparisons need double quotes. =IF(A2=Paid, ...) makes Excel look for a name called Paid and returns #NAME?.
  • In nested IFs, the order of tests matters, because the first true test wins. Test the most restrictive condition first, such as >=85 before >=70.
  • A number stored as text compares as text. "50" counts as greater than 1000, because text always sorts above numbers. Convert it with VALUE first.
  • Typing thresholds and rates into the formula hides them. Put them in cells and use references, so a change is made in one place.
  • More than three nested IFs is a sign to switch to IFS, SWITCH or a lookup table.

Questions people ask

How do I use IF with multiple conditions?

Put AND or OR inside the test: `=IF(AND(B2>=18, C2="Yes"), "Eligible", "No")` needs both conditions. `=IF(OR(A2="East", A2="West"), "Coastal", "Inland")` needs either one.

How many IFs can I nest?

Excel allows 64 levels. In practice, stop at three. Past that, IFS, SWITCH or a lookup table is easier to read and to change.

Why does my IF return FALSE?

The test was false and the value_if_false argument was left out. Add a third argument, such as `""` or `0`.

Is IF case-sensitive?

No. `=IF(A2="paid", ...)` is true for "Paid" and "PAID". For a case-sensitive test use EXACT: `=IF(EXACT(A2, "Paid"), ...)`.

How do I return a blank with IF?

Use empty text, `""`, as the result. Note that the cell then holds a formula that returns empty text, not a truly empty cell, so ISBLANK on it returns FALSE.

Learn IF in a real sheet.

IF is taught in Excel foundations, lesson 15: IF: your first decision. Each lesson is a short, graded exercise like the one above.