Menu

Nested IF in Excel: Multiple IF Statements with Examples

=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F"))) puts one IF inside another to choose between more than two results. Learn how nested IF is read, why the order of the conditions matters, and when IFS or a lookup table is the better choice.

Every sheet on this page is live: change a number or a formula and it recalculates.

A nested IF is an IF inside another IF, used when there are more than two possible results. =IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F"))) gives an A for 90 or more, a B for 80 to 89, a C for 70 to 79, and an F below 70.

Grades from scores
C2
ABC
1StudentScoreGrade
2Ana94A
3Ben81B
4Chloe70C
5Dan65F
6Eve88B
7Finn90A
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Click C2 and look at the formula bar: three IF functions, three closing brackets at the end. Change Dan's score in B5 to 75 and his grade turns from F to C.

How a nested IF is read

Excel reads the formula from the start and stops at the first test that is TRUE:

=IF(B2>=90, "A",
   IF(B2>=80, "B",
      IF(B2>=70, "C",
         "F")))
  1. Is the score 90 or more? Then A, and nothing else is checked.
  2. Otherwise, is it 80 or more? Then B. This test does not need to say "and below 90", because a score of 90 or more never reaches it.
  3. Otherwise, is it 70 or more? Then C.
  4. Otherwise F, the value_if_false of the last IF.

Each inner IF sits in the value_if_false slot of the one before it. Excel allows up to 64 levels, but a formula with more than four or five is hard to check by eye. Excel accepts line breaks inside a formula, so you can lay out a long one like this in the formula bar: press Alt+Enter (Windows) or Control+Option+Return (Mac) before each IF.

Why the order of conditions matters

Because Excel stops at the first TRUE test, the thresholds must go from the highest to the lowest when you use >=. Column D has the same three tests in the opposite order:

Same tests, wrong order
D2
ABCD
1StudentScoreRight orderWrong order
2Ana94AC
3Ben81BC
4Chloe70CC
5Dan65FF
6Eve88BC
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

In column D everyone with 70 or more gets a C: a score of 94 passes the first test, B2>=70, and the B and A tests are never reached. If you prefer to start with the lowest band, flip the operators: =IF(B2<70,"F",IF(B2<80,"C",IF(B2<90,"B","A"))) gives the same grades as column C.

Nested IF with text

The tests can compare text too. Here the delivery fee depends on the region, and every region not named gets the last value:

Delivery fee by region
C2
ABC
1OrderRegionFee
21001North$5.00
31002South$7.00
41003West$9.00
51004East$6.00
61005Islands$9.00
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

West and Islands match none of the three tests and get the final value, $9.00. When every test compares the same cell with a fixed value, as here, SWITCH writes the same rule with each region once: =SWITCH(B2,"North",5,"South",7,"East",6,9). See the SWITCH page.

Nested IF with AND

A nested IF can combine its levels with AND or OR when one band depends on two cells. A rep with sales of 2,000 or more and at least 3 years gets 10%, anyone else over 2,000 gets 5%, and the rest get nothing:

Commission rate
D2
ABCD
1RepSalesYearsRate
2Ana2400410%
3Ben210015%
4Chloe150060%
5Dan3000310%
6Eve90020%
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Ana and Dan qualify for 10%, Ben has the sales but not the years and gets 5%, and Chloe and Eve get 0%. The order matters here too: the stricter test comes first.

IFS: the same thing without nesting

In Excel 2019, Excel 2021 and Microsoft 365, IFS takes the tests and results as pairs, with no inner IF and one closing bracket. TRUE as the last test acts as "everything else":

=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")

It reads the conditions in the same order and stops at the first TRUE one, so the order rule above still applies. The IFS page covers it, including the #N/A it returns when no test matches. In Excel 2016 and earlier IFS is not available, and a file using it shows #NAME? there.

Practice: a three-band commission

Commission
C2
ABC
1RepSalesCommission
2Ana$6,200
3Ben$2,400
4Chloe$600
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In C2, pay 10% of the sales in B2 when they are 5000 or more, 5% when they are 1000 or more, and 0 otherwise. The formula fills down to C4.

A lookup table instead of many IFs

When the bands are numbers and there are more than three or four of them, keep the thresholds in a small table and look them up. The table is sorted from the lowest threshold up, and approximate match (TRUE as the last argument) returns the row of the largest threshold that is not above the score:

Grades from a band table
C2
ABCDEF
1StudentScoreGradeMin scoreGrade
2Ana94A0F
3Ben81B70C
4Chloe70C80B
5Dan65F90A
6Eve88B
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

The results match the nested IF at the top of the page. To move the B band to 85, change E4 to 85: no formula changes, and every grade updates. With XLOOKUP the same lookup is =XLOOKUP(B2,$E$2:$E$5,$F$2:$F$5,,-1), where -1 means "exact match or the next smaller value"; the table does not need to be sorted then.

Try it: the band table is ready, write the lookup.

Grade with VLOOKUP
C2
ABCDEF
1StudentScoreGradeMin scoreGrade
2Ana860F
370C
480B
590A
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

Your turn: In C2, return the grade for the score in B2 from the band table in E2:F5.

Frequently Asked Questions

How do you write multiple IF statements in Excel?

Put the next IF in the value_if_false argument of the previous one: =IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F"))). Excel tests the conditions from the first to the last and stops at the first one that is TRUE.

How many IF functions can you nest in Excel?

Up to 64 levels in Excel 2007 and later. Well before that limit, a formula becomes hard to read and to check; with more than three or four bands, a lookup table with approximate VLOOKUP or XLOOKUP is easier to maintain.

Why does my nested IF return the wrong result?

Usually because the conditions are in the wrong order. With >= tests, start with the highest threshold: if B2>=70 comes first, a score of 95 stops there and gets the 70 band's result.

What can I use instead of nested IF in Excel?

IFS in Excel 2019 and later (=IFS(B2>=90,"A",B2>=80,"B",TRUE,"F")), SWITCH when you compare one value with fixed values, and a lookup table with =VLOOKUP(B2,$E$2:$F$5,2,TRUE) for numeric bands.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED