Sub topic 8
Nesting IF for More Than Two Outcomes
Assume you know how to enter formulas, use cell references such as B2, and write a basic IF formula with true and false results. This chapter builds several decisions into one formula.
A basic IF has two possible outcomes. For example:
=IF(B2>=50, "Pass", "Fail")Sometimes a result needs more categories. A score might receive an A, B, C, or F. To create these outcomes, place another IF formula inside the false result of the first IF. This technique is called nesting.
How a nested IF works
Suppose the score in B2 uses these rules:
| Score | Grade |
|---|---|
| 90 or more | A |
| 80–89 | B |
| 70–79 | C |
| Below 70 | F |
The nested formula is:
=IF(B2>=90, "A", IF(B2>=80, "B", IF(B2>=70, "C", "F")))Google Sheets evaluates the formula from left to right:
- It checks whether
B2is at least 90. - If that test is true, it returns
"A"and stops. - If it is false, it checks whether
B2is at least 80. - If that test is also false, it checks whether
B2is at least 70. - If every test is false, it returns
"F".
For a score of 85, the first test fails. The second test succeeds, so the result is "B".
The final "F" is the fallback value. It covers every score that did not match an earlier condition.
Put conditions in the right order
The order of the tests matters. Start with the highest threshold and move downward. If you test B2>=70 first, a score of 95 matches that condition and receives "C" before Sheets reaches the test for 90.
This version is therefore incorrect for the grading rules:
=IF(B2>=70, "C", IF(B2>=80, "B", IF(B2>=90, "A", "F")))The first true test wins. Arrange overlapping conditions so that the most specific or highest-priority condition appears first.
A useful way to plan a nested formula is to write the rules as a decision path:
flowchart TD
A[Read score in B2] --> B{B2 >= 90?}
B -- Yes --> C[Return A]
B -- No --> D{B2 >= 80?}
D -- Yes --> E[Return B]
D -- No --> F{B2 >= 70?}
F -- Yes --> G[Return C]
F -- No --> H[Return F]Match the parentheses
Each nested IF has its own opening and closing parentheses. The general pattern is:
=IF(test1, result1, IF(test2, result2, IF(test3, result3, fallback)))There are three IF functions, so the formula ends with three closing parentheses. A missing parenthesis produces a formula parse error.
Write the formula in stages if it becomes difficult to read:
=IF(B2>=90, "A", "Other")Then replace "Other" with the next decision:
=IF(B2>=90, "A", IF(B2>=80, "B", "Other"))Finally, replace the remaining fallback with the last test:
=IF(B2>=90, "A", IF(B2>=80, "B", IF(B2>=70, "C", "F")))Use nested IF with other results
The returned values do not have to be letters. They can be numbers, labels, or calculations:
=IF(B2>=100, B2*0.2, IF(B2>=50, B2*0.1, 0))This returns a 20% commission for values of 100 or more, a 10% commission for values from 50 through 99, and zero otherwise.
Keep each condition and result easy to inspect. Deeply nested formulas are harder to maintain, especially when rules change. For many branches, a flatter function such as IFS can be easier to read, but nested IF is useful when you need a clear final fallback or when working with an existing formula.
Exercise
Write a formula that returns "High" for a value in B2 of 100 or more, "Medium" for 50 through 99, and "Low" for anything below 50.
Show answer
=IF(B2>=100, "High", IF(B2>=50, "Medium", "Low"))