formulastreak

Lookup function

XLOOKUP function in Google Sheets and Excel

XLOOKUP finds a value in one range and returns the value in the same position of another range, in any direction.

Checked against Microsoft's and Google's documentation on · Example calculated on a live sheet

Syntax

XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])

Arguments in [brackets] are optional. Google Sheets writes it XLOOKUP(search_key, lookup_range, result_range, missing_value, [match_mode], [search_mode]).

Example

=XLOOKUP(B2,$G$2:$G$8,$I$2:$I$8) reads: Look for B2 (the order's SKU) in the price list's SKU column G2:G8, and return the value from the same row of the Price column I2:I8.

Orders and price list · edit D2 and watch it recalculate
Click a cell (or use the arrow keys) to insert its address · Enter shows the resultD2 = $34.00
ABCDEFGHIJ
1OrderSKUQtyPriceSKUProductPriceStock
22001PL-1042$34.00PL-101Fern$9.5040
32002PT-2101$12.50PL-104Monstera$34.0012
42003TL-3013$18.00PL-107Snake plant$22.0025
52004PL-1011$9.50PT-210Terracotta pot$12.5060
62005SL-4014$7.25PT-212Ceramic pot$19.0018
72006PL-1041$34.00TL-301Watering can$18.009
82007PT-2122$19.00SL-401Potting mix$7.2580
92008PL-1071$22.00

D2 shows $34.00: PL-104 is found in G3, so XLOOKUP returns I3, the Monstera's price.

How the spreadsheet calculates it

Looks for B2 in $G$2:$G$8 and returns the value in the same position of $I$2:$I$8. If there's no match, it gives #N/A.

  1. 1. XLOOKUP: Looks for B2 in $G$2:$G$8 and returns the value in the same position of $I$2:$I$8. If there's no match, it gives #N/A.
    • key = `B2`: what to look for
    • lookup_range = `$G$2:$G$8`: where to look for it
    • return_range = `$I$2:$I$8`: what to bring back, the same height

More XLOOKUP examples

  • =XLOOKUP(A2,$G$2:$G$8,$I$2:$I$8,"Not found")The price for the SKU in A2, with a message when it's missing.
  • =XLOOKUP(D2,$G$2:$G$6,$H$2:$H$6,,-1)The grade for the score in D2: the largest boundary at or below it.
  • =XLOOKUP(E2,$A$2:$A$100,$B$2:$D$100)Three columns for one key, spilled across.
  • =XLOOKUP(1,(B2:B17=H1)*(C2:C17=H2),E2:E17)A lookup on two conditions at once.

Paste any of these into the formula explainer to see it step by step.

Tips

  • Lock both ranges with $ before filling down, so every row searches the same list.
  • Give if_not_found a clear message ("Not found") rather than hiding the miss as 0, so gaps in the data stay visible.
  • Keep the lookup and return ranges on the same rows; a one-row offset silently returns the neighbour's value.

What XLOOKUP is used for

Pulling a price, a manager or a status from a master list into a report, matching transactions to a customer list, and grading or banding values with match mode -1 instead of a long nested IF.

Arguments

ArgumentRequiredWhat it is
lookup_valueYesWhat to look for, usually a cell like B2.Watch out: A stray space or a number stored as text never matches: #N/A.
lookup_arrayYesThe single row or column to search.
return_arrayYesThe range to return from; it must line up with lookup_array.Watch out: Starting it on a different row returns values from the wrong row.
if_not_foundNoWhat to show instead of #N/A when nothing matches, such as "Not found".
match_modeNo0 exact (the default), -1 exact or next smaller, 1 exact or next larger, 2 wildcard.
search_modeNo1 first to last (the default), -1 last to first, 2 and -2 binary search on sorted data.

Common mistakes

  • Return and lookup ranges of different heights: #VALUE!.

  • Sharing a file with someone on Excel 2019: they'll see #NAME?.

  • Using it in a file that someone opens in Excel 2019 or older, where it shows #NAME?.

  • Leaving the ranges unlocked when filling down: lock them with $ so every row searches the same list.

In Google Sheets

Google Sheets has XLOOKUP with the same six arguments in the same order, so formulas move between the two apps unchanged.

Errors you may see with XLOOKUP

  • #N/A: The lookup value isn't in lookup_array (often a space or a text-number mismatch) and there's no if_not_found. How to fix it.
  • #NAME?: The file is open in a version without XLOOKUP (Excel 2019 or older).
  • #SPILL!: The lookup value is a whole column, or return_array is several columns and the cells to the right aren't empty. How to fix it.

Questions

Can XLOOKUP return several columns?

Yes. Give it a return_array several columns wide, such as $H$2:$I$8, and the result spills across: product and price from one formula.

How do I find the last match?

Set search_mode to -1: XLOOKUP(key, keys, results, , 0, -1) searches from the bottom, so it returns the last matching row.

Is XLOOKUP better than VLOOKUP?

Where everyone has it, yes: exact match by default, no column number to miscount, looks left, and a built-in not-found value. See VLOOKUP vs XLOOKUP.

What's the difference between match mode -1 and search mode -1?

Match mode -1 accepts the next smaller value when there's no exact match (for bands and tiers). Search mode -1 changes the direction: it searches from the last row up, so it finds the last match.

Sources

Official documentation the facts on this page were checked against.

Practise XLOOKUP on a live sheet

Lesson 17, XLOOKUP (Unit 4, Lookups), has 4 graded exercises, checked instantly, with steps and hints when you're stuck. Pro