How-to recipes · Analysis
How to use nested IF and IFS in Excel
Assign grades, bands or tiers with nested IF, the clearer IFS function, SWITCH for exact values, or a lookup table that is easier to maintain.
Many decisions have more than two outcomes: a score becomes a grade from A to F, an order total selects a discount band, a number of years of service decides the holiday allowance. With a single IF you can only return two results, so people put IFs inside IFs. That works, but each extra level adds brackets and makes mistakes easier. This recipe compares the three main approaches: nested IF (every version), the IFS function (Excel 2019 and later), and a lookup table, which is often the best of all.
The example data
Five students and their scores in A1:B6. The grading rule: 90 or more is A, 80-89 B, 70-79 C, 60-69 D, below 60 F.
Microsoft 365, Excel 2021 and 2019: IFS
IFS takes pairs of condition, result and returns the result of the first condition that is TRUE:
| A | B | C | |
|---|---|---|---|
| 1 | Student | Score | Grade |
| 2 | Ana | 93 | A |
| 3 | Ben | 78 | |
| 4 | Chloe | 85 | |
| 5 | Dev | 59 | |
| 6 | Eva | 70 |
93 meets the first condition, so the grade is A.
Result: A
Copied down, the grades are A, C, B, F, C. The final pair TRUE,"F" acts as everything else: TRUE is always true, so any score that failed all previous tests gets F. Without it, a score below 60 would return #N/A, which is IFS's way of saying no condition matched.
In Microsoft 365 the formula can grade the whole column at once: =IFS(B2:B6>=90,"A",B2:B6>=80,"B",B2:B6>=70,"C",B2:B6>=60,"D",TRUE,"F") spills five grades.
Excel 2016 and earlier: nested IF
Each IF handles one level and passes everything else to the next IF in its value_if_false argument:
=IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C",IF(B2>=60,"D","F"))))It returns exactly the same grades. Count the closing brackets: one per IF, all at the end. Excel allows up to 64 nested IFs, but anything over three or four levels is hard to read and easy to break. IF and logical formulas: AND, OR, NOT, IFS and SWITCH shows how to build them step by step.
B2>=60, a score of 93 returns D, because 93 is also at least 60. Test the highest threshold first when using >=, or the lowest first when using <.Often better: a lookup table
Put the thresholds in a small table, sorted from lowest to highest, and let a lookup in approximate match mode find the right band. The rule is visible in the sheet and can be changed without touching any formula:
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Student | Score | Grade | Min | Grade | |
| 2 | Ana | 93 | A | 0 | F | |
| 3 | Ben | 78 | 60 | D | ||
| 4 | Chloe | 85 | 70 | C | ||
| 5 | Dev | 59 | 80 | B | ||
| 6 | Eva | 70 | 90 | A |
E2:F6 is the grading table. Match mode -1 means: exact match, or the next smaller value.
Result: A
For 93 the next smaller threshold is 90, so XLOOKUP returns A. In Excel 2016 and 2019 use =VLOOKUP(B2,$E$2:$F$6,2,TRUE) or =LOOKUP(B2,$E$2:$E$6,$F$2:$F$6); both require the thresholds in ascending order. Adding an A+ band for 97 or more is now one new row instead of another level of brackets. See Lookup guide: VLOOKUP vs INDEX/MATCH vs XLOOKUP.
Exact values: SWITCH
When you map exact values rather than ranges, SWITCH (Excel 2019 and later) is cleaner than IFS. It compares one expression with a list of values: =SWITCH(D2,"N","North","S","South","E","East","W","West","Unknown") turns region codes into names, with Unknown as the default. SWITCH cannot test >=, so it is not suited to grade bands.
Which one to use
| Approach | Best for | Versions |
|---|---|---|
| Nested IF | 2-3 outcomes, maximum compatibility | All |
| IFS | 3-6 outcomes with different conditions | 2019, 2021, 365 |
| SWITCH | Exact codes mapped to results | 2019, 2021, 365 |
| Lookup table | Bands and tiers that may change; many outcomes | All (XLOOKUP in 2021/365) |
Pitfalls
- Gaps and overlaps.
B2>90andB2<90leave exactly 90 without a grade. Use>=consistently. - Text numbers. A score stored as text is compared as text and always counts as greater than any number, so it gets an A. Convert the column first.
- Blank scores count as 0 and get F. Wrap the formula:
=IF(B2="","",IFS(...)). - IFS in old versions. A workbook using IFS shows
#NAME?in Excel 2016. Use nested IF or a lookup table if colleagues have older versions.