Sub topic 9
A cleaner option: the IFS function
This chapter assumes you can write an IF formula, use comparison operators, and nest IF calls. It also assumes you can copy a formula down a column with the fill handle. Nested IF works, but long chains are hard to read. The IFS function does the same job in a flatter form.
Why nested IF gets hard to read
Here is the grading formula from the nested IF chapter:
=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F")))Each new outcome adds another IF( and another closing parenthesis at the end. With six or seven outcomes, it is easy to lose count of the brackets. A missing bracket makes Excel reject the formula or return the wrong result.
The IFS syntax
IFS takes pairs of arguments. Each pair is a logical test followed by the value to return when that test is true.
=IFS(test1, value1, test2, value2, test3, value3, ...)Excel checks the tests from left to right. It returns the value that belongs to the first test that is true, then stops. This is the same "first true test wins" rule that nested IF uses.
Here is the grading formula rewritten with IFS:
=IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F")Read it as a list of rules:
- If B2 is at least 90, return "A".
- Otherwise, if B2 is at least 80, return "B".
- Otherwise, if B2 is at least 70, return "C".
- Otherwise, return "F".
There is only one closing parenthesis, and each test sits next to the result it controls.
The final TRUE acts as the default
An IF formula always has a "value if false" argument, so it always returns something. IFS has no such argument. If none of the tests is true, IFS returns the #N/A error.
To supply a default, end the list with TRUE as the last test. TRUE is always true, so it catches every value that failed the earlier tests. In the grading formula, TRUE,"F" means "for everything else, return F".
Order still matters
IFS stops at the first true test, so the order of your tests changes the result. Suppose you reverse the grading tests:
=IFS(B2>=70,"C",B2>=80,"B",B2>=90,"A",TRUE,"F")A score of 95 passes the first test (>=70), so the formula returns "C". The later tests never run. As with nested IF, test the strictest condition first when you use >=. If you use <= or <, start with the smallest threshold instead.
IFS with a threshold cell
IFS works with the thresholds you learned to store in cells. If the cut-offs sit in F1, F2, and F3, use absolute references so they stay fixed when you copy the formula down:
=IFS(B2>=$F$1,"A",B2>=$F$2,"B",B2>=$F$3,"C",TRUE,"F")Now you can change a grade boundary in one cell, and every result updates.
IFS and nested IF compared
| Point | Nested IF | IFS |
|---|---|---|
| Readability with many outcomes | Gets harder with each level | Stays flat |
| Default result | The last "value if false" | A final `TRUE` test |
| No test is true | Returns the last false value | Returns `#N/A` unless you add `TRUE` |
| Excel versions | All versions | Excel 2019 and later, and Microsoft 365 |
Version compatibility
IFS is not available in Excel 2016 or earlier. If you open a workbook that uses IFS in one of those versions, the formula shows an error such as #NAME?. Use nested IF if the file will be shared with people on older versions.
When to choose which
- Use plain IF when there are two outcomes.
- Use IFS when there are three or more outcomes that depend on one chain of tests.
- Use nested IF when the file must work in older Excel versions.
- Combine IFS with AND or OR when a rule needs more than one condition, for example
AND(B2>=60,C2>=60)as one of the tests.
Exercise
A sheet has sales figures in B2. Write an IFS formula that returns "High" for 5000 or more, "Medium" for 1000 or more, and "Low" for anything else. What does the formula return for a value of 250, and what would happen if you left out the final TRUE test?
Show answer
=IFS(B2>=5000,"High",B2>=1000,"Medium",TRUE,"Low"). For 250, the first two tests fail and TRUE catches it, so the result is "Low". Without the final TRUE test, 250 would match nothing and the formula would return #N/A.
Exercise
This formula is meant to grade scores, but a score of 95 returns "C". Why, and how do you fix it? =IFS(B2>=70,"C",B2>=80,"B",B2>=90,"A",TRUE,"F")
Show answer
IFS stops at the first true test, and 95 is at least 70, so it returns "C" immediately. Put the strictest test first: =IFS(B2>=90,"A",B2>=80,"B",B2>=70,"C",TRUE,"F").