# How to replace a long nested IF with a lookup table in Excel

Put the categories and results in a small table and look them up: =XLOOKUP(B2,$E$2:$E$6,$F$2:$F$6,"Standard").

**Excel:** `=XLOOKUP(B2,$E$2:$E$6,$F$2:$F$6,"Standard")` (Excel 2021, 2024 and Microsoft 365)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F |
| --- | --- | --- | --- | --- | --- |
| Item | Category | Ship class |  | Category | Class |
| Desk lamp | Lighting |  |  | Furniture | Freight |
| Sofa | Furniture |  |  | Lighting | Parcel |
| Rug | Textiles |  |  | Textiles | Parcel |
| Bookcase | Furniture |  |  | Electronics | Insured |
| Monitor | Electronics |  |  | Glassware | Fragile |
| Vase | Glassware |  |  |  |  |
| Throw pillow | Textiles |  |  |  |  |
| Garden hose | Outdoor |  |  |  |  |

Formula in C2, filled to C9: `=XLOOKUP(B2,$E$2:$E$6,$F$2:$F$6,"Standard")`

Result: Parcel; Freight; Parcel; Freight; Insured; Fragile; Parcel; Standard

## How it works

XLOOKUP finds the category in `E2:E6` and returns the class from the same row of `F2:F6`. The fourth argument is the default for categories that aren't in the table, like Outdoor. Adding a category is a new row in the table, not another level of IF.

## Other ways

- `=IFNA(VLOOKUP(B2,$E$2:$F$6,2,FALSE),"Standard")`: The same table with VLOOKUP, for Excel 2019 and earlier.
- `=IF(B2="Furniture","Freight",IF(OR(B2="Lighting",B2="Textiles"),"Parcel",IF(B2="Electronics","Insured",IF(B2="Glassware","Fragile","Standard"))))`: The nested IF the table replaces. It works, but every change means editing every copy of the formula.

## Common mistakes

- Lock the table with $ before filling down, or it slides off the data.
- A category spelled differently ("Electronic") falls through to the default without any error. Use a dropdown for the category column.
- If a category appears twice in the table, XLOOKUP returns the first one.

## Questions

**What if the categories are number ranges?**

List the lower bound of each band and use an approximate match: `=XLOOKUP(B2,E2:E6,F2:F6,,-1)`.

**Does this work in Google Sheets?**

Yes, XLOOKUP works there too. VLOOKUP with FALSE is the classic alternative in both apps.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/replace-nested-if-with-lookup-table
