Excel guide · 5 min read
MATCH vs XMATCH: what's different and which to use
Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Item | Bin | Counted | Up to (kg) | Rate | |
| 2 | Desk lamp | B-04 | 12 | 1 | 4.5 | |
| 3 | Monitor arm | C-11 | 7 | 2 | 6 | |
| 4 | Desk mat | B-02 | 30 | 5 | 8.5 | |
| 5 | Laptop stand | C-03 | 15 | 10 | 12 | |
| 6 | Desk lamp | B-04 | 9 | 20 | 18 | |
| 7 | USB-C hub | A-08 | 22 | |||
| 8 | Cable tray | D-01 | 18 | |||
| 9 | Webcam | A-02 | 11 |
Download this sheet as an Excel practice file (.xlsx)
The syntax side by side
MATCH(lookup_value, lookup_array, [match_type]) has three arguments. match_type is 1 (the default: the largest value less than or equal to the lookup value, data sorted ascending), 0 (exact) or -1 (the smallest value greater than or equal to it, data sorted descending).
XMATCH(lookup_value, lookup_array, [match_mode], [search_mode]) has four. match_mode is 0 (the default: exact), -1 (exact or next smaller), 1 (exact or next larger) or 2 (wildcards). search_mode is 1 (first to last, the default), -1 (last to first), 2 (binary search on data sorted ascending) or -2 (binary search on data sorted descending).
With an exact match, both give the same answer. Desk lamp is the first item in this stock count, so both return 1. Neither is case-sensitive: "desk LAMP" finds the same row.
Result: 1
1: Desk lamp is the first item in A2:A9. =MATCH("Desk lamp",A2:A9,0) returns 1 too, but only because of the 0.
The default is the trap: MATCH without 0
Leave off MATCH's third argument and you get an approximate match that assumes the list is sorted A to Z. On an unsorted list of names it doesn't return #N/A when it should; it can return a wrong position with no warning, and INDEX then pulls a value from the wrong row. That's the most common MATCH bug, and it's why most MATCH formulas you see end in ,0.
XMATCH flips the default. =XMATCH("Desk lamp",A2:A9) is already exact, and a value that isn't in the list gives #N/A instead of a neighbour. If you only take one thing from this page: in MATCH always type the 0 when you want an exact match.
Next smaller vs next larger: the rate table
The table in E1:F6 is a courier price list read as "up to": parcels up to 1 kg cost 4.50, up to 2 kg cost 6, up to 5 kg cost 8.50, and so on. A 3.2 kg parcel belongs in the up-to-5 kg band.
MATCH's default finds the next smaller value, 2, so it returns the up-to-2 kg band and undercharges. To get the next larger value, MATCH needs match_type -1 and the list sorted largest first, which means re-sorting your table. XMATCH with match_mode 1 finds the next larger value whatever the order.
Result: 8.5
8.5: the up-to-5 kg rate. =INDEX(F2:F6,MATCH(3.2,E2:E6)) returns 6, the up-to-2 kg rate, because MATCH rounds down.
Find the last match: search from the bottom
Desk lamp was counted twice, and the recount further down the list is the one that matters. MATCH always returns the first match. XMATCH with search_mode -1 starts at the bottom and returns the position of the last one, still counted from the top of the list, so INDEX can use it as it is.
In MATCH you'd need a workaround such as LOOKUP(2,1/(A2:A9="Desk lamp"),C2:C9), which is harder to read and to explain to whoever opens the file next.
Result: 9
9: the later recount. XMATCH("Desk lamp",A2:A9,0,-1) alone returns 5, the fifth row of the list.
Wildcards work differently
MATCH with 0 treats * and ? as wildcards automatically, so =MATCH("Monitor*",A2:A9,0) returns 2. XMATCH treats them as ordinary characters unless you ask: =XMATCH("Monitor*",A2:A9) looks for the literal text Monitor* and returns #N/A. Set match_mode to 2 to switch wildcards on.
The flip side: if your data really contains an asterisk or question mark, such as a part called AB*12, MATCH with 0 reads it as a wildcard unless you write AB~*12. XMATCH's exact mode finds it as typed.
Result: 2
2: Monitor arm, the first item starting with Monitor.
Binary search, versions and which to pick
XMATCH's search_mode 2 (ascending) and -2 (descending) use binary search, which halves the list at each step and is much faster on very long sorted lists. On unsorted data it returns wrong positions without an error, just like MATCH's approximate modes, so only use it on data you sort and keep sorted.
XMATCH exists in Excel for Microsoft 365, Excel 2021 and later, and Excel for the web. Open the file in Excel 2019 or older and the formula shows #NAME?, with _xlfn.XMATCH in the formula bar. MATCH works in every version.
Pick XMATCH when everyone has Excel 365 or 2021: the exact default prevents the classic bug, and next-larger, last-match and wildcard lookups need no workarounds. Pick MATCH with 0 when the workbook goes to people on older versions. INDEX with either one is still the way to look up to the left or return a row and column position; XLOOKUP is simpler when you just want the value.
Common mistakes
MATCH with the third argument left off on an unsorted list
Add 0 for an exact match, or switch to XMATCH, which is exact by default.
Expecting XMATCH to understand * and ? like MATCH does
Set match_mode to 2: =XMATCH("Monitor*",A2:A9,2).
Using MATCH -1 on a list sorted smallest first
MATCH -1 needs descending order. Use XMATCH with match_mode 1 instead and leave the table as it is.
Binary search mode on data that isn't sorted
Sort the lookup column first, or use the default search mode.
FAQ
Is XMATCH better than MATCH?
For most people on Excel 365 or 2021, yes: it's exact by default, finds the next larger value without sorting, and can search from the last item. MATCH is still the choice when the file must work in older versions.
Is XMATCH faster than MATCH?
For ordinary exact lookups the difference is small. XMATCH's binary search modes are much faster on very long sorted lists, and MATCH's approximate mode also uses a fast search on sorted data.
Why does XMATCH return #N/A when MATCH finds the value?
Usually because of wildcards: MATCH with 0 reads * and ? as wildcards, XMATCH doesn't unless match_mode is 2. Also check for extra spaces or numbers stored as text, which break both.
Does XMATCH work in Excel 2019?
No. XMATCH needs Excel for Microsoft 365, Excel 2021 or later, or Excel for the web. In Excel 2019 it shows #NAME?.
Can XMATCH return a value instead of a position?
Not by itself. Wrap it in INDEX, like =INDEX(C2:C9,XMATCH("Webcam",A2:A9)), or use XLOOKUP, which returns the value directly.
Functions used
MATCHPosition of a valueXMATCHPosition of a value, modernINDEXValue at a positionLOOKUPApproximate lookup in sorted dataXLOOKUPModern lookup in any direction
Related guides
- How to use INDEX MATCH in Excel
- How to find the row number of a value in Excel
- INDEX MATCH vs XLOOKUP
- How to find the last value in a column in Excel
- How to find the longest streak in Excel
- How to calculate the payback period in Excel
Updated