Going Stellar

Home/Google Sheets reference

Google Sheets function · Lookup

XLOOKUP in Google Sheets: syntax and examples

XLOOKUP searches one range and returns the value from the same position in another. It looks in either direction, takes a fallback for misses, and can return the first or the last match. It covers what VLOOKUP, HLOOKUP and INDEX with MATCH did separately.

Syntax

XLOOKUP(search_key, lookup_range, result_range, missing_value, [match_mode], [search_mode])

Arguments

ArgumentTypeRequiredWhat it does
search_keyanyyesThe value to find.
lookup_rangerangeyesOne row or column to search. It can sit anywhere, left or right of the result.
result_rangerangeyesWhat to return, same height or width as lookup_range. A wider range returns the whole row.
missing_valueanynoReturned when nothing matches. Left out, a miss gives #N/A.
match_modenumberno0 exact (default), -1 exact or next smaller, 1 exact or next larger, 2 wildcard.
search_modenumberno1 first to last (default), -1 last to first, 2 or -2 binary search on sorted data.

Examples

The examples use this table, starting in A1:

SKUProductPriceStock
A-100Desk lamp3412
A-200Office chair5490
B-300Monitor stand129.57
B-400Cable tray79.940
A-100Desk lamp XL993
=XLOOKUP("Cable tray", B2:B6, A2:A6)

Result: B-400

The key is in column B and the result in column A. XLOOKUP looks left, VLOOKUP cannot.

Run in a Google Sheet (English US locale) on .

=XLOOKUP("C-999", A2:A6, C2:C6, "not found")

Result: not found

A fourth argument replaces #N/A, so no IFERROR is needed.

Run in a Google Sheet (English US locale) on .

=XLOOKUP("A-100", A2:A6, B2:B6, "", 0, -1)

Result: Desk lamp XL

The code appears twice. search_mode -1 starts from the bottom and returns the last one.

Run in a Google Sheet (English US locale) on .

=XLOOKUP(100, C2:C6, B2:B6, "", 1)

Result: Monitor stand

match_mode 1 finds the exact price or the next larger one: 129.5, Monitor stand.

Run in a Google Sheet (English US locale) on .

=XLOOKUP("B-*", A2:A6, B2:D6, "", 2)

Result:

Monitor stand129.57

A wildcard needs match_mode 2. A wider result_range returns the whole row across.

Run in a Google Sheet (English US locale) on .

Common errors

  • Without missing_value a miss returns #N/A. Put your own text as the fourth argument, or an empty string "" to skip it before match_mode.
  • Wildcards (* and ?) work only with match_mode 2. In the default mode, "B-*" is searched as literal text and returns #N/A.
  • lookup_range and result_range must have the same length. B2:B5 against A2:A6 returns #N/A.
  • With duplicates the first match wins. Use search_mode -1 to take the last one.

Compared with Excel

Same syntax as Excel XLOOKUP. Excel names the fourth argument if_not_found.

Sources

  1. XLOOKUP (Docs Editors Help)

Markdown version · All functions