Sub topic 3
Nesting IF for more than two outcomes
This chapter assumes you can write a basic IF formula, refer to cells such as B2, copy formulas down a column, and use the comparison operators (=, <>, >, <, >=, <=).
Nesting IF
A nested IF puts one IF inside the valueiffalse argument of another. Sheets tests the conditions in order and returns the result of the first true one, so list the highest threshold first.
=IF(B2>=90, "A", IF(B2>=80, "B", IF(B2>=70, "C", "F")))A cleaner alternative: IFS
IFS takes pairs of test and result with no nesting. End with TRUE as a default. Without it, a score that matches no test returns #N/A.
=IFS(B2>=90, "A", B2>=80, "B", B2>=70, "C", TRUE, "F")Catching errors with IFERROR
IFERROR returns a replacement value when a formula produces an error such as #DIV/0!.
=IFERROR(IF(B2/C2>0.5, "High", "Low"), "Check data")One formula for the whole column with ARRAYFORMULA
Enter ARRAYFORMULA once in the first result cell. It fills every row below and leaves blank rows in column A empty.
=ARRAYFORMULA(IF(A2:A="", "", IF(B2:B>=50, "Pass", "Fail")))Common mistakes and how to fix them
- Missing quotes: text such as Pass must be in double quotes. Without them, Sheets returns #NAME?.
- Mismatched parentheses: every opening ( needs a closing ). Count them in nested formulas.
- Wrong nesting order: testing B2>=70 first sends every high score to "C".
- Omitted third argument: =IF(B2>=50, "Pass") returns FALSE when the test fails.
Exercise
Write a formula that returns "Honors" if B2 is 90 or higher, "Pass" if B2 is 50 or higher, and "Fail" otherwise. Use IFS.
Show answer
=IFS(B2>=90, "Honors", B2>=50, "Pass", TRUE, "Fail")