
The Ultimate XLOOKUP & XMATCH Lookup Guide (Two-Way, Variable Columns, Nth, and Last Matches in 1 Minute)
Stop memorizing VLOOKUP column numbers. XLOOKUP looks up values both to the left and right and handles default values, multi-column returns, and last/nth matches all at once.
Syntax & Key Options
| Function | Syntax | Key point |
|---|---|---|
| XLOOKUP | =XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode]) | Default values, exact/approximate matches, forward/backward searches, and multi-column returns (spills) |
| XMATCH | =XMATCH(lookup_value, lookup_array, [match_mode], [search_mode]) | Returns the relative position (index) and can search from the first or last item |
match_mode: 0 = exact match; -1 = exact match or next smaller item; 1 = exact match or next larger item; 2 = wildcard match. search_mode: 1 = search first to last; -1 = search last to first.
Basic Lookups (Exact/Approximate)
Example 1) Find a price by product code (exact)
=XLOOKUP(F2, Products[Code], Products[Price], "Not found")
Example 2) Approximate match from a threshold table (score → grade)
=XLOOKUP(F2, Grade[Cutoff], Grade[Level], , -1) // exact match or next smaller item
Two-Way Lookups & Multi-Column Returns
Example 3) Return a customer’s address and phone number at the same time
=XLOOKUP(F2, Customers[Name], HSTACK(Customers[Address], Customers[Phone])) // spill
Example 4) A 2D lookup based on both row and column
=XLOOKUP(Product, Table[Product], XLOOKUP(Region, Table[[#Headers],[Seoul]:[Busan]], Table[[Seoul]:[Busan]]))
Multiple-Criteria (AND/OR) Lookups
Example 5) Combined region + product key
=XLOOKUP(F2&"|"&G2, RegionColumn&"|"&ProductColumn, Sales)
Example 6) OR (first match among multiple candidates)
=XLOOKUP({F2,G2,H2}, CodeColumn, Price) // returns results when the first spilled candidate matches
Nth and Last Items
Example 7) Last order amount (customer = F2)
=XLOOKUP(F2, CustomerColumn, AmountColumn, , 0, -1) // search from last to first
Example 8) Nth match (customer = F2, N = K2)
=LET(m, FILTER(AmountColumn, CustomerColumn=F2), INDEX(m, K2))
Calculating Positions with XMATCH
Example 9) Find a product’s column position and pass it to CHOOSECOLS
=LET(p, XMATCH(G2, Table[#Headers]), TAKE(CHOOSECOLS(Table, p), , ))
Example 10) Sort, then use a binary search (faster for large datasets)
=XMATCH(F2, SORTBY(CodeColumn, CodeColumn), 0, 2) // 2 = binary search (ascending order)
Mistakes & Performance Checklist
- Numbers stored as text → Standardize formats with VALUE/TEXT before looking up values.
- Range size → Make sure lookup_array and return_array have matching lengths.
- Default value → Provide a message or value in
if_not_found(improves report quality). - Performance → Cache frequently used ranges with
LET; if needed, usesearch_mode=2(binary search) with sorted data. - Multi-column returns → Keep cells to the right or below clear so the spill range does not overlap.
Summary
| Goal | Typical formula |
|---|---|
| Exact lookup + default value | XLOOKUP(key, LookupColumn, ReturnColumn, "Not found") |
| Approximate range | XLOOKUP(x, ThresholdColumn, ResultColumn, , -1/1) |
| Last match | XLOOKUP(key, Column, Value, , 0, -1) |
| Multiple criteria | XLOOKUP(Criterion1&"|"&Criterion2, Column1&"|"&Column2, Value) |
| Multi-column return | XLOOKUP(key, Column, HSTACK(Return1,Return2,...)) |
FAQ
Which row is returned when the same key appears more than once?
By default, the first match is returned. With search_mode=-1, the last match is returned. Use FILTER if you need all matching rows.
Is it safe when columns are added or reordered?
Yes. Because XLOOKUP uses range references, it avoids VLOOKUP’s col_index_num issue.