XLOOKUP Function
The Excel XLOOKUP function finds a value in one range and returns the aligned value from another range, using exact matching by default.
| Excel XLOOKUP Function | |||||||||||
| XLOOKUP finds a key and returns the aligned value, with exact matching by default. | |||||||||||
| Source data, editable | Examples | ||||||||||
| Key | Item | Price | Region | Example | Formula syntax | Result | |||||
| P-101 | Notebook | $12.50 | South | Exact price | =XLOOKUP("P-104",A12:A18,C12:C18) | $24.50 | |||||
| P-102 | Marker Set | $8.75 | North | Return leftward region | =XLOOKUP("P-102",A12:A18,D12:D18) | North | |||||
| P-103 | Desk Tray | $18.00 | East | Last duplicate status | =XLOOKUP("T-7",A12:A18,D12:D18,"Not found",0,-1) | Closed | |||||
| P-104 | Task Lamp | $24.50 | North | Custom not found | =XLOOKUP("P-999",A12:A18,C12:C18,"Not found") | Not found | |||||
| T-7 | Ticket | $1.00 | Open | ||||||||
| T-9 | Ticket | $1.00 | Pending | ||||||||
| T-7 | Ticket | $1.00 | Closed | ||||||||
| Reliability checks | |||||||||||
| Exact lookup returns the visible P-104 price | OK | ||||||||||
| Reverse search returns the final T-7 status | OK | ||||||||||
Overview
The Excel XLOOKUP function searches one range for a key and returns the value in the corresponding position of another range. It defaults to exact matching, can return values from either side of the lookup range, and includes explicit controls for missing keys, duplicate keys, approximate matches, and search direction.
Quick reference
Syntax: =XLOOKUP(lookup_value, lookup_array, return_array, [if_not_found], [match_mode], [search_mode])
Returns: The aligned value or array from return_array, or the specified not-found value. (other)
Arguments:
lookup_value(required) — The value to find.lookup_array(required) — The one-dimensional range or array to search.return_array(required) — The aligned range or array containing the result.if_not_found(optional) — A controlled result returned when no match exists.match_mode(optional) — Controls exact, approximate, or wildcard matching; exact match is the default.search_mode(optional) — Controls search direction or a sorted-data binary search.
The lookup value, one-dimensional lookup array, and aligned return array are required. Optional arguments provide a not-found result, matching mode, and search direction; exact matching is the default.
Common uses
- Retrieve a price, category, owner, or status from an ID.
- Return values located to the left of a lookup key.
- Find the latest record when a key appears more than once.
- Replace missing-key errors with a controlled message.
Calculations
XLOOKUP finds lookup_value inside lookup_array, identifies its relative position, and returns the item at that position from return_array. The lookup and return ranges must align, but the return range may sit to the left or right of the lookup range.
Exact matching is the default. If duplicates exist, the default search returns the first match; search_mode=-1 returns the last. The optional if_not_found value handles only the no-match case without concealing unrelated errors.
Binary search modes can improve performance on large sorted ranges, but they require the data to be sorted in the corresponding direction. Using them on unsorted data can return a plausible but incorrect result.
Function behavior
Situation | Behavior |
|---|---|
Exact match | Default behavior when |
Lookup to either side | Supported because |
Duplicate keys | First match by default; last match with |
Missing key | Returns |
Wildcards | |
Binary search | Requires correctly sorted lookup data. |
Return array with multiple columns | Can spill more than one corresponding value. |
Common errors
Misaligned lookup and return ranges
What happens:
The arrays do not describe corresponding positions, so the formula errors or returns the wrong record.
Better approach:
Use bounded ranges with the same lookup dimension.
Binary search on unsorted data
What happens:
The formula can return an invalid match without an obvious warning.
Better approach:
Use the default linear search unless the range is deliberately sorted and maintained for binary search.
Expecting the last duplicate by default
What happens:
The first occurrence is returned.
Better approach:
Set search_mode to -1 when the final occurrence is the intended record.
Example
Example 1 — Exact Price Lookup
=XLOOKUP("P-104",A12:A18,C12:C18)
On XLOOKUP Example, this returns $24.50, the price aligned with key P-104.
Example 2 — Return a Value from Another Direction
=XLOOKUP("P-102",A12:A18,D12:D18)
This returns North. XLOOKUP references the return range directly, so it does not rely on a hardcoded column index.
Example 3 — Return the Last Duplicate
=XLOOKUP("T-7",A12:A18,D12:D18,"Not found",0,-1)
The key T-7 appears twice. With exact matching and a last-to-first search, the formula returns the final status, Closed.
Example workbook
The workbook contains XLOOKUP Example and Notes. The example sheet provides seven editable synthetic records and four live formulas for exact lookup, a separate return column, reverse duplicate search, and custom not-found handling. Two checks confirm the price lookup and final duplicate status, and both display OK.
Key takeaway
Use XLOOKUP for an exact, direction-independent lookup; add an explicit not-found result and a reverse search only when the data requires them.