A nested IF places one IF function inside another, so Excel can check several conditions one after another. The inner IF goes in the value_if_false part of the outer one. Nesting is useful when there are more than two possible results, such as grade bands, shipping tiers or commission levels.
What a nested IF looks like
Say column A holds test scores, and you want an A for 90 or more, a B for 80 to 89, a C for 70 to 79, and an F for anything lower. In B2, the formula is:
=IF(A2>=90, "A", IF(A2>=80, "B", IF(A2>=70, "C", "F")))
Read it from the outside in. The first test asks whether A2 is 90 or more. If that is false, Excel moves to the IF in the third argument and tests whether A2 is 80 or more. The formula keeps going until one test is true, or until it reaches the final “F”, which is the result when none of the earlier tests passed.
Three IF functions mean three pairs of parentheses, which you’ll notice as you type.
Build it one step at a time
Long nested formulas are easier to write in layers. Start with the first test and a simple “everything else” result:
- Enter
=IF(A2>=90, "A", "Other")and check it with a score of 95 and a score of 85. - Replace “Other” with the next test:
=IF(A2>=90, "A", IF(A2>=80, "B", "Other")). Check again. - Keep adding layers until the last result is a plain value such as “F”, not another test.
- Test the boundaries: 90, 89, 80, 79, 70, 69 and a blank cell.
Testing the boundaries is where most mistakes show up. A formula can look right for typical values and still be off by one at a cut-off.
Order matters
Excel stops at the first test that is TRUE and returns its result. It doesn’t check the rest, so the order of the tests decides the answer.
Take this version:
=IF(A2>=70, "C", IF(A2>=90, "A", IF(A2>=80, "B", "F")))
A score of 95 is at least 70, so the first test is TRUE and the formula returns “C”. The A branch is never reached. For “>=” tests, check the highest threshold first, then work downward.
Keep the parentheses matched
Each IF needs its own closing parenthesis, and the formula only works when every opening one has a partner. When you click next to a parenthesis in the formula bar, Excel highlights its match, which makes the count easier to check. If Excel shows a message when you press Enter, count the parentheses first.
Combine conditions inside a level
Any test in a nested IF can use AND or OR. For example, a bonus that needs both a sales target and a completed course can sit inside one level of the formula. The use of AND and OR inside IF is covered in how to use and or with if in excel.
When nesting gets hard to read
Once a formula goes beyond three or four levels, it becomes hard to follow and to change. Two alternatives help in different situations:
- IFS lists the tests and results in one flat sequence. It is covered in ifs function in excel vs nested if, with the same grade example written both ways.
- SWITCH works well when one value is matched against several fixed options. See excel switch function example.
If the bands are stored in a table, such as a list of minimum scores and grades, a lookup can find the band for you. The approximate-match setting in VLOOKUP does this for sorted lists, and vlookup exact match vs approximate match explains how that setting behaves. A table also means changing a cut-off doesn’t require rewriting the formula.
Test a nested IF with Evaluate Formula
If a result is wrong, step through the formula instead of guessing. The Evaluate Formula tool on the Formulas tab shows each part of the formula and the value it produces at each step. How to use evaluate formula in excel walks through that process.
Common problems
- The last IF has no false value. If the innermost IF is missing its final argument, a false test shows FALSE instead of a grade. Always give the innermost IF a final result.
- Tests overlap. Checking “>=70” before “>=90” is the most common cause of a wrong band.
- Text results without quotes. Text typed without quotes, such as Pass, is read as a name and returns #NAME?.
For more causes, see why is my if formula not working in excel.