XMATCH function
Returns the position of an item in a row, column or array, with exact match by default and options to search backwards or find the next larger item.
Available in Microsoft 365, Excel 2021 and later, Excel for the web, Excel for Mac 2021+
Excel 2021 and laterNot in Google Sheets
Syntax
XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])| Argument | What it means | |
|---|---|---|
lookup_value | Required | The value to find. |
lookup_array | Required | The row, column or array to search. |
match_mode | Optional | 0 exact (default), -1 exact or next smaller, 1 exact or next larger, 2 wildcard match. |
search_mode | Optional | 1 first to last (default), -1 last to first, 2 binary search ascending, -2 binary search descending. |
Returns: The position (a whole number) of the match within lookup_array.
How XMATCH works
XMATCH is the modern version of MATCH. It tells you the position of a value in a list - 1 for the first item, 2 for the second, and so on - and is usually combined with INDEX or used to drive other formulas. The important difference is the default: XMATCH looks for an exact match unless you say otherwise, which removes the most common MATCH mistake.
Its match_mode lets you ask for the next smaller or next larger item when there is no exact match, and unlike MATCH it does not need the list to be sorted for that. search_mode -1 searches from the bottom up, which finds the last occurrence of something - the latest order by a rep, the most recent price change. Note that the position is still counted from the top, even when searching backwards.
XMATCH can also accept an array of lookup values and return an array of positions that spills, which is useful inside SORTBY or CHOOSECOLS.
Examples
1Column position of a heading
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Region | Q1 | Q2 | Q3 | Q4 |
| 2 | North | 12500 | 14200 | 13900 | 16100 |
| 3 | South | 9800 | 10400 | 11250 | 12030 |
| 4 | East | 7600 | 8150 | 8900 | 9420 |
| 5 | |||||
| 6 | 3 |
Result: 3
Q3 is the third cell of B1:E1. No third argument is needed because exact matching is the default.
2Last order by a rep
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Order | Rep | Amount | ||
| 2 | SO-201 | Tom | 450 | 5 | |
| 3 | SO-202 | Ana | 1200 | ||
| 4 | SO-203 | Tom | 380 | ||
| 5 | SO-204 | Raj | 960 | ||
| 6 | SO-205 | Tom | 720 | ||
| 7 | SO-206 | Ana | 310 |
Result: 5
Searching from the bottom (-1), the first Tom found is in B6, which is position 5 of B2:B7. Wrap it in INDEX to get the order: =INDEX(A2:A7, XMATCH("Tom", B2:B7, 0, -1)) returns SO-205.
3Smallest box that fits
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Box | Capacity (litres) | ||
| 2 | S | 20 | L | |
| 3 | M | 45 | ||
| 4 | L | 80 | ||
| 5 | XL | 120 |
Result: L
No box holds exactly 60 litres, so match mode 1 picks the next larger capacity, 80 (position 3), and INDEX returns its size.
Common errors and how to fix them
| Error | Why it happens | Fix |
|---|---|---|
#N/A | The value is not in the list (or, with mode -1/1, there is no smaller/larger item). | Check the data or wrap in IFNA. |
#VALUE! | match_mode or search_mode is not one of the allowed numbers. | Use 0, -1, 1 or 2 for match_mode and 1, -1, 2 or -2 for search_mode. |
Tips
- Binary search modes (
2,-2) are very fast on huge sorted lists but return wrong results if the data is not sorted. =XMATCH(E2:E4, A2:A10)returns three positions at once.- For wildcard matching set match_mode to 2:
=XMATCH("*Khan", B2:B5, 2).
Questions
Should I replace MATCH with XMATCH?
In workbooks used only on Excel 2021 or Microsoft 365, yes - XMATCH is safer by default. Keep MATCH for files that must open in older versions.
Does XMATCH count from the bottom when searching backwards?
No. It searches from the bottom but still reports the position counted from the top of the range.
Google Sheets
Use MATCH(search_key, range, 0) for exact positions, or XLOOKUP returning a SEQUENCE of positions for reverse or wildcard searches.
XMATCH in other languages
In a non-English version of Excel the function has a local name. Excel translates formulas automatically when a file is opened in another language.
| Language | Function name |
|---|---|
| Danish | XSAMMENLIGN |
| Dutch | X.VERGELIJKEN |
| Finnish | XVASTINE |
| French | EQUIVX |
| German | XVERGLEICH |
| Hungarian | XHOL.VAN |
| Italian | CONFRONTA.X |
| Norwegian (Bokmål) | XSAMSVAR |
| Polish | X.DOPASUJ |
| Portuguese (Brazil) | CORRESPX |
| Portuguese (Portugal) | CORRESPX |
| Russian | ПОИСКПОЗX |
| Spanish | COINCIDIRX |
| Swedish | XMATCHNING |
| Turkish | ÇAPRAZEŞLEŞTİR |
Recipes that use XMATCH
- How to find duplicates between two lists in Excel
- How to look up a value to the left in Excel
- How to rank numbers with ties in Excel