How to write nested IF statements
✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)Chain several IF tests for multi-way decisions — grades, tiers, status labels.
The formula
| App | Formula | Notes |
|---|---|---|
| Excel (desktop) | =IF(A2>=90,"A",IF(A2>=80,"B",IF(A2>=70,"C","F"))) | Each IF's 'else' slot holds the next IF. On Excel 2019+/Sheets, IFS is the flatter alternative. |
| Google Sheets | =IF(A2>=90,"A",IF(A2>=80,"B",IF(A2>=70,"C","F"))) | Identical. |
| LibreOffice Calc | =IF(A2>=90,"A",IF(A2>=80,"B",IF(A2>=70,"C","F"))) | Identical. |
How it works
A nested IF puts the next IF where the previous one's "value if false" goes, so the tests run in order until one is true: 85 fails >=90, passes >=80, so it stops at "B". Order matters — arrange tests from most to least restrictive, or an early loose test grabs everything. The last IF's false-slot is your catch-all ("F" here). Beyond ~3-4 levels nesting gets unreadable and error-prone; switch to IFS (=IFS(A2>=90,"A",A2>=80,"B",...,TRUE,"F")) or a lookup table with the closest-match pattern, both easier to maintain.
Verified, not just documented
We ran =IF(A2>=90,"A",IF(A2>=80,"B",IF(A2>=70,"C","F"))) in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned B — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned B for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.
Functions used
IF — see full Excel, Google Sheets & LibreOffice compatibility for each.
Related recipes
- How to compare two columns row by row
- How to concatenate cells that meet a condition (TEXTJOIN IF)
- How to convert Yes/No (or TRUE/FALSE) to 1 and 0
- How to fill blank cells with the value above
- How to find duplicate values in a column