Section: Excel & Google Sheets

XMATCH in Excel returns the position of a value in a list. =XMATCH(4,{5,4,3,2,1}) returns 2, because 4 is the second entry. It is the newer version of MATCH, with exact matching as the default, a wildcard mode, and four search modes including a reverse search that finds the last entry rather than the first. This guide covers the syntax, each mode with the example Microsoft publishes, a two-way lookup built with INDEX, and when to use XLOOKUP instead.
What XMATCH returns
Microsoft describes XMATCH as searching for an item in an array or range and returning its relative position. A position, not a value. If the list is names and you ask for a name, you get a number, and that number is only useful once you feed it to INDEX or to another function that takes a row or column number.
The distinction matters in practice. People expect a lookup to hand back a value, and then wonder why XMATCH returns 4. It is doing what it says: 4 means the fourth entry.
Which versions have it
Microsoft lists XMATCH for Excel for Microsoft 365 on Windows and Mac, Excel 2024 on Windows and Mac, Excel for the web, and Excel 2021 on Windows and Mac. It is not listed for Excel 2019 or 2016, where the name is not recognised and the formula shows #NAME?. If a workbook has to run on older versions, MATCH is the portable choice.
The syntax
=XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])
- lookup_value is required and is the value you are looking for.
- lookup_array is required and is the range or array to search.
- match_mode is optional and sets the match type. The default is 0, an exact match.
- search_mode is optional and sets the direction or the algorithm. The default is 1, first to last.
The four match modes
The match mode is where most of the flexibility lives, and Microsoft defines exactly four values:
- 0 is an exact match and is the default. If nothing matches, you get #N/A.
- -1 is an exact match or the next smallest item. Useful for bands and thresholds where you want the lower bound.
- 1 is an exact match or the next largest item. Useful for tiers where you want the first value that clears a bar.
- 2 is a wildcard match, where the asterisk, question mark and tilde have their usual meaning.
The wildcard mode is the one that replaces the old habit of setting MATCH's third argument to 0 and then wondering why * did not work. In XMATCH you ask for it deliberately with 2.

The four search modes
- 1 searches first to last and is the default.
- -1 searches last to first, which returns the most recent matching entry when a list grows downward.
- 2 performs a binary search on data sorted in ascending order. Microsoft warns that if the array is not sorted that way, the result will be invalid.
- -2 performs a binary search on data sorted in descending order, with the same warning.
The binary modes are fast on long lists and dangerous on unsorted ones. A wrong answer with no error is worse than a slow one, so use them only when you control the sort order.

A first example
Microsoft's first example has a list of products in C3:C7 and a search value in E3. The formula is =XMATCH(E3,C3:C7,1), with a match mode of 1 so that it accepts an exact match or the next largest item, and it returns 2 because Grape, the closest match to the text in E3, sits second in the list.
The same formula on a value that is already in the list returns the exact position, which is the common case. The tier behaviour only shows up when the value is missing.

Counting with a sorted list
Microsoft's second example asks how many salespeople qualified for a bonus. The sales figures sit in C3:C9 sorted from highest to lowest, the threshold is in F2, and the formula is =XMATCH(F2,C3:C9,1). It returns 4, because the fourth value is the first one at or above the threshold, and everything above it also qualifies.
That is a trick worth knowing and worth labelling in the sheet: it counts only because the list is sorted. Reverse the sort order and the same formula returns a position that means nothing.
A two-way lookup with INDEX
XMATCH becomes genuinely useful when you nest two of them inside INDEX. Microsoft's third example returns a sales figure for one representative and one month from a grid in C6:E12, with names in B6:B12 and months in C5:E5:
=INDEX(C6:E12,XMATCH(B3,B6:B12),XMATCH(C3,C5:E5))
The first XMATCH finds the row of the representative, the second finds the column of the month, and INDEX reads the cell where they meet. It is the old INDEX and MATCH pattern with fewer arguments and an exact match by default, so a typo in the name returns #N/A instead of the nearest row.

XMATCH compared with MATCH
MATCH takes a match_type of 1, 0 or -1 and defaults to 1, which is an approximate match on sorted data. That default has caused more wrong answers than any other lookup setting in Excel, because a formula copied from an old sheet silently returns the nearest value instead of an error.
XMATCH flips that: the default is exact, the modes are named more clearly, and the search direction is a separate argument rather than a side effect of the match type. The other gain is the reverse search, which answers "when did this last happen" without sorting the list backwards.
XMATCH compared with XLOOKUP
XLOOKUP returns the value itself, so for most lookups it is the shorter answer and XMATCH is not needed. Reach for XMATCH when the position is the thing you want: to feed INDEX, to count qualifying rows, to find the last occurrence of an entry, or to locate a row number that another formula needs.
If you want every match rather than one position, FILTER returns all the rows that qualify. Wrap the result in IFERROR when a missing value is normal, so the cell shows a dash instead of #N/A.
Common problems
- #N/A on a value you can see. Trailing spaces or a number stored as text. TRIM the list, or compare text with text.
- The wrong position from a binary search. Search mode 2 or -2 on data that is not sorted the way the mode assumes.
- A position that changes when the list is sorted differently. Positions depend on order. If the order is not fixed, look up a key instead of a row number.
- #NAME? on a colleague's machine. Excel 2019 or 2016. Use MATCH there.
- A wildcard that matches nothing. Wildcards need match mode 2. The default treats * as a character.
Questions and answers
Does XMATCH return the value or the position?
The position, as a number. Wrap it in INDEX to get the value.
What is the default match mode?
0, an exact match. That is the main difference from MATCH, whose default is approximate.
How do I find the last matching row?
Use a search mode of -1, which searches from the bottom of the range upward.
Can XMATCH search two dimensions at once?
Not on its own. Use two XMATCH calls inside INDEX, one for the row and one for the column.
Is XMATCH case sensitive?
No. It ignores case, as MATCH does. For a case-sensitive match, use EXACT inside an array formula or SUMPRODUCT.
