Spreadsheet Practice

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

Formula (Excel and Google Sheets)

=XLOOKUP(B2,$E$2:$E$6,$F$2:$F$6,"Standard")

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

Result on the example
one result per row in C2, filled down to C9
Works in
Excel 2021, 2024 and Microsoft 365
Google Sheets
Same formula

See it work

The formula is already in C2, filled down to C9. Change any input and the result updates, or edit the formula to experiment.

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.

=XLOOKUP(B2,$E$2:$E$6,$F$2:$F$6,"Standard")

Result"Parcel"

  1. B2"Lighting"

    The value in B2.

  2. $E$2:$E$65 rows × 1 col: "Furniture", "Lighting", "Textiles", "Electronics", …

    A range: 5 cells in one column.

  3. $F$2:$F$65 rows × 1 col: "Freight", "Parcel", "Parcel", "Insured", …

    A range: 5 cells in one column.

  4. XLOOKUP(B2,$E$2:$E$6,$F$2:$F$6,"Standard")"Parcel"

    XLOOKUP: Searches one range and returns the matching item from another.

    • lookup_valueB2"Lighting"
    • lookup_array$E$2:$E$65 rows × 1 col: "Furniture", "Lighting", "Textiles", "Electronics", …
    • return_array$F$2:$F$65 rows × 1 col: "Freight", "Parcel", "Parcel", "Insured", …
    • if_not_found"Standard"

In Google Sheets

The same formula works in Google Sheets: =XLOOKUP(B2,$E$2:$E$6,$F$2:$F$6,"Standard"). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=IFNA(VLOOKUP(B2,$E$2:$F$6,2,FALSE),"Standard")Parcel, Freight, Parcel…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"))))Parcel, Freight, Parcel…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.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Replace a long nested IF with a lookup table

In C2, return the ship class for the item's category from the table in E2:F6, or "Standard" when the category isn't listed. Fill down to C9.

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.

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.