Lookup & reference function

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])
ArgumentWhat it means
lookup_valueRequiredThe value to find.
lookup_arrayRequiredThe row, column or array to search.
match_modeOptional0 exact (default), -1 exact or next smaller, 1 exact or next larger, 2 wildcard match.
search_modeOptional1 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

B6fx=XMATCH("Q3", B1:E1)
ABCDE
1RegionQ1Q2Q3Q4
2North12500142001390016100
3South9800104001125012030
4East7600815089009420
5
63

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

E2fx=XMATCH("Tom", B2:B7, 0, -1)
ABCDE
1OrderRepAmount
2SO-201Tom4505
3SO-202Ana1200
4SO-203Tom380
5SO-204Raj960
6SO-205Tom720
7SO-206Ana310

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

D2fx=INDEX(A2:A5, XMATCH(60, B2:B5, 1))
ABCD
1BoxCapacity (litres)
2S20L
3M45
4L80
5XL120

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.

⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 16 KB

Common errors and how to fix them

ErrorWhy it happensFix
#N/AThe 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.

LanguageFunction name
DanishXSAMMENLIGN
DutchX.VERGELIJKEN
FinnishXVASTINE
FrenchEQUIVX
GermanXVERGLEICH
HungarianXHOL.VAN
ItalianCONFRONTA.X
Norwegian (Bokmål)XSAMSVAR
PolishX.DOPASUJ
Portuguese (Brazil)CORRESPX
Portuguese (Portugal)CORRESPX
RussianПОИСКПОЗX
SpanishCOINCIDIRX
SwedishXMATCHNING
TurkishÇAPRAZEŞLEŞTİR

Recipes that use XMATCH