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
- Excel 2016
- Excel 2019
- Excel 2021
- Excel 2024
- Microsoft 365
- Google Sheets
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.
| A | B | C | D | E | F | G | H | I | J | |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Order | SKU | Qty | Price | SKU | Product | Price | Stock | ||
| 2 | 2001 | PL-104 | 2 | $34.00 | PL-101 | Fern | $9.50 | 40 | ||
| 3 | 2002 | PT-210 | 1 | $12.50 | PL-104 | Monstera | $34.00 | 12 | ||
| 4 | 2003 | TL-301 | 3 | $18.00 | PL-107 | Snake plant | $22.00 | 25 | ||
| 5 | 2004 | PL-101 | 1 | $9.50 | PT-210 | Terracotta pot | $12.50 | 60 | ||
| 6 | 2005 | SL-401 | 4 | $7.25 | PT-212 | Ceramic pot | $19.00 | 18 | ||
| 7 | 2006 | PL-104 | 1 | $34.00 | TL-301 | Watering can | $18.00 | 9 | ||
| 8 | 2007 | PT-212 | 2 | $19.00 | SL-401 | Potting mix | $7.25 | 80 | ||
| 9 | 2008 | PL-107 | 1 | $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. XLOOKUP: Looks for
B2in$G$2:$G$8and 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 forlookup_range=`$G$2:$G$8`: where to look for itreturn_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
| Argument | Required | What it is |
|---|---|---|
| lookup_value | Yes | What to look for, usually a cell like B2.Watch out: A stray space or a number stored as text never matches: #N/A. |
| lookup_array | Yes | The single row or column to search. |
| return_array | Yes | The 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_found | No | What to show instead of #N/A when nothing matches, such as "Not found". |
| match_mode | No | 0 exact (the default), -1 exact or next smaller, 1 exact or next larger, 2 wildcard. |
| search_mode | No | 1 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.