XMATCH in Excel: A More Powerful Replacement for MATCH

XMATCH Function in Excel Feature Image
XMATCH does everything MATCH does, but better. It defaults to exact match so you never accidentally return a wrong result, can find the last occurrence in a list, supports wildcards in a dedicated mode, and adds next-larger approximate matching that MATCH cannot do at all. This guide covers the full syntax, a direct comparison table, and six examples from basic position lookup through two-way INDEX+XMATCH and binary search on large datasets.

If you have ever used the MATCH function inside an INDEX formula, you already understand the concept behind XMATCH — it finds the position of a value in a list. But XMATCH does it better in almost every way. It defaults to exact match (so you never accidentally get the wrong result), can search from the last item rather than the first, supports wildcard partial matching with a dedicated mode, and works on both vertical and horizontal ranges without any adjustment. This guide covers the full syntax, a direct MATCH vs XMATCH comparison, and six practical examples.

Availability: XMATCH is available in Microsoft 365, Excel 2024, and Excel 2021 only. It is not available in Excel 2019 or earlier. For older versions, the MATCH function remains the correct choice.

XMATCH Syntax

XMATCH returns the relative position of a value in an array — a number telling you which row (or column) the match was found in.

=XMATCH(lookup_value, lookup_array, [match_mode], [search_mode])
ArgumentRequired?What it means
lookup_value Required The value to search for — a cell reference, text in quotes, or a number.
lookup_array Required The single column or single row to search in. Unlike VLOOKUP, the lookup does not need to be in a specific position — any column or row works.
match_mode Optional 0 = exact match (default — safe). -1 = exact match or next smaller. 1 = exact match or next larger. 2 = wildcard match (* and ?).
search_mode Optional 1 = search first to last (default). -1 = search last to first (finds the last match). 2 = binary search ascending. -2 = binary search descending.
What XMATCH returns: XMATCH always returns a position number — the row or column number within the lookup_array where the match was found. By itself this number is not very useful. Pair XMATCH with INDEX to retrieve the actual value at that position: =INDEX(return_range, XMATCH(value, lookup_range)).

XMATCH vs MATCH — Key Differences

Feature MATCH (old) XMATCH (new)
Default match type Approximate match (1) — dangerous on unsorted data Exact match (0) — safe by default, no extra argument needed
Exact match syntax Requires 0 as third argument: =MATCH(val, range, 0) Just two arguments: =XMATCH(val, range)
Next larger value Not supported — only next smaller match_mode = 1 — returns exact or next larger
Reverse search (last match) Not supported — always finds first match search_mode = -1 — finds the last match
Wildcard matching Works in mode 0 — wildcards always active Explicit mode 2 — wildcards only when you ask for them
Binary search Not available search_mode 2 or -2 — faster on large sorted datasets
Availability All Excel versions Excel 365, 2024, 2021 only

Example 1: Basic Exact Match — Find Position in a List

In its simplest form, XMATCH needs only two arguments and returns the row number of the matching value within the lookup range. This is cleaner than MATCH because you do not need to remember to add the 0.

1
Find the position of a product in a list
#
A — Product
B — Price
1
Laptop
$1,200
2
Monitor
$320
3
Keyboard
$85
4
Mouse
$45
XMATCH — only 2 arguments needed, defaults to exact match: =XMATCH("Keyboard", A1:A4) Result: 3 (Keyboard is the 3rd item in the range) MATCH equivalent — requires the 0 for exact match: =MATCH("Keyboard", A1:A4, 0) Result: 3 (same result, but the 0 is mandatory) With a cell reference as the lookup value: =XMATCH(E2, A1:A4)
XMATCH returns 3 because "Keyboard" is the third item in A1:A4. No third argument needed — exact match is the default.

Example 2: INDEX + XMATCH — The Modern Lookup Combination

XMATCH by itself only returns a position number. Its real power comes when paired with INDEX — XMATCH finds the row, INDEX retrieves the value. Together they replace VLOOKUP with a formula that can look in any direction and does not break when columns are inserted.

2
Look up a price by product name — INDEX + XMATCH
Retrieve the price (col B) for the product in cell E2: =INDEX(B1:B4, XMATCH(E2, A1:A4)) E2 = "Keyboard" -> XMATCH returns 3 -> INDEX returns $85 Return a value to the LEFT of the search column (VLOOKUP cannot do this): =INDEX(A1:A4, XMATCH(E2, B1:B4)) Search column B (Price), return column A (Product name) Two-way lookup — row and column position both from XMATCH: =INDEX(C2:E8, XMATCH(G2, A2:A8), XMATCH(H2, C1:E1)) G2 = row label, H2 = column label (e.g. "Sales Rep" + "Month")
INDEX + XMATCH vs XLOOKUP: Both combinations achieve similar results for most lookups. Use INDEX + XMATCH when you need to return a value from a range that is separate from the lookup range, or when you need the two-way lookup pattern. Use XLOOKUP for simpler single-value lookups with built-in error handling. Both are available in the same Excel versions.

Example 3: Reverse Search — Find the Last Occurrence

MATCH always returns the position of the first match in a list. If a value appears multiple times and you need the last one — for example, the most recent date for a repeating item — set search_mode to -1. XMATCH then searches from the bottom upward.

3
Find the position of the last occurrence of a value in a list
#
A — Product
B — Date
C — Price
1
Laptop
01-Jan-2026
$1,200
2
Monitor
01-Feb-2026
$320
3
Laptop
01-Feb-2026
$1,100
4
Laptop
01-Mar-2026
$980 (most recent)
search_mode 1 (default) — finds FIRST match (row 1 = $1,200): =INDEX(C1:C4, XMATCH("Laptop", A1:A4)) Result: $1,200 (oldest price) search_mode -1 — finds LAST match (row 4 = $980): =INDEX(C1:C4, XMATCH("Laptop", A1:A4, 0, -1)) Result: $980 (most recent price) MATCH cannot do this — it always returns the first match position
search_mode -1 makes XMATCH scan from the last row upward, returning row 4 (the most recent Laptop entry) rather than row 1 (the oldest). MATCH has no equivalent capability.

Example 4: Wildcard Partial Match

When you set match_mode to 2, XMATCH activates wildcard matching — * matches any sequence of characters and ? matches a single character. This is useful when you only know part of a value, such as searching for "Puma" when the list contains "Puma Co." or "Puma Ltd."

4
Find a company by partial name when the full registered name is different
#
A — Registered Name
B — Revenue
1
Contoso Holdings Ltd
$4.2M
2
Puma Co.
$2.8M
3
Fabrikam Inc
$1.9M
match_mode 2 enables wildcards. Search for anything starting with "Puma": =XMATCH("Puma*", A1:A3, 2) Result: 2 ("Puma Co." matches "Puma*") Return the revenue using INDEX: =INDEX(B1:B3, XMATCH("Puma*", A1:A3, 2)) Result: $2.8M Contains search (partial match anywhere in the value): =INDEX(B1:B3, XMATCH("*Contoso*", A1:A3, 2)) Result: $4.2M Dynamic — search term in cell E2, add wildcard in formula: =INDEX(B1:B3, XMATCH(E2&"*", A1:A3, 2))
Explicit wildcard mode is safer: With MATCH, wildcards like * and ? are always active even in exact match mode (mode 0), which can cause unexpected matches. With XMATCH, wildcards are only treated as wildcards in mode 2 — in all other modes, * and ? are treated as literal characters. This makes XMATCH safer when your data genuinely contains asterisks or question marks.

Example 5: Approximate Match — Find the Closest Value

XMATCH's match_mode -1 and 1 support approximate matching for banded ranges — useful for commission tiers, tax brackets, and discount thresholds. Unlike MATCH, XMATCH does not require sorted data for approximate matching, and it adds "next larger" support that MATCH cannot provide.

5
Find the discount tier for a customer's order value
A — Min Order
B — Discount
0
0%
500
5%
1000
10%
2000
15%
Order value = 1350. Find discount tier (exact or next smaller): =INDEX(B1:B4, XMATCH(1350, A1:A4, -1)) 1350 not found, next smaller is 1000 (row 3), returns 10% Find exact or NEXT LARGER (match_mode = 1): =INDEX(B1:B4, XMATCH(1350, A1:A4, 1)) Next larger is 2000 (row 4), returns 15% MATCH equivalent — only supports next smaller, requires sorted data: =INDEX(B1:B4, MATCH(1350, A1:A4, 1)) MATCH mode 1 = next smaller, but data MUST be sorted ascending
Sorting for approximate match: MATCH's approximate mode requires sorted data — on unsorted data it silently returns wrong results. XMATCH's approximate modes are more forgiving on smaller unsorted ranges, but for best reliability and performance on large datasets, sort the lookup array before using approximate matching.

Example 6: Count Items Meeting a Threshold

Because XMATCH returns a position, you can use its approximate match modes creatively to count how many items in a sorted list fall above or below a threshold — without COUNTIF, without sorting manually, and without helper columns.

6
Count how many salespeople met or exceeded a $10,000 target
A — Salesperson
B — Sales (sorted asc)
Dana
$6,200
Sam
$8,900
Carlos
$11,400
Alice
$14,700
Ben
$18,200
Count people who met or exceeded $10,000 target (sales sorted ascending): XMATCH finds position of the threshold, subtract gives count above it: =COUNTA(B1:B5) - XMATCH(10000, B1:B5, -1) Result: 5 - 2 = 3 (Carlos, Alice, Ben all exceeded $10,000) Simpler alternative using COUNTIF: =COUNTIF(B1:B5, ">=10000") Result: 3 (same answer — use COUNTIF for straightforward counts) Where XMATCH threshold counting is more useful — binary search on huge datasets: XMATCH(10000, B1:B1000000, -1, 2) search_mode 2 = binary search — much faster on millions of sorted rows
Binary search for large datasets: For sorted arrays with hundreds of thousands of rows, set search_mode to 2 (sorted ascending) or -2 (sorted descending). Binary search is orders of magnitude faster than a linear scan — essential for dashboards processing very large datasets.

Troubleshooting XMATCH Errors

#N/A error — value not found

No item in lookup_array matches the lookup_value. Check for trailing spaces, data type mismatches (text vs number), or the value genuinely not existing. Wrap with IFERROR for a user-friendly fallback: =IFERROR(INDEX(B:B, XMATCH(E2, A:A)), "Not found").

#VALUE! error

An invalid value was passed to match_mode or search_mode. Valid match_mode values are 0, -1, 1, 2. Valid search_mode values are 1, -1, 2, -2. Any other number returns #VALUE!.

Wrong result from approximate match

Approximate match modes (-1 and 1) work most reliably on sorted data. On unsorted data, results may be unpredictable — particularly when using binary search (modes 2 and -2), which requires the array to be sorted in the matching direction. Sort your lookup array before using approximate match for guaranteed accuracy.

XMATCH not available in older Excel

You are on Excel 2019 or earlier. Use =MATCH(value, range, 0) for exact match, and consider upgrading to Microsoft 365 for the full dynamic array function suite.

Frequently Asked Questions

  • What does the XMATCH function do in Excel?+
    XMATCH searches for a value in a range or array and returns its relative position — a number indicating which row or column it was found in. It is the modern replacement for MATCH, with safer defaults (exact match by default), reverse search, wildcard matching, and binary search for large datasets. XMATCH is almost always paired with INDEX to retrieve an actual value from that position.
  • What is the difference between XMATCH and MATCH?+
    The five key improvements are: XMATCH defaults to exact match (MATCH defaults to approximate — dangerous); XMATCH can find the next larger value (MATCH cannot); XMATCH can search from last to first (MATCH cannot); XMATCH has an explicit wildcard mode so wildcards are only active when you want them; and XMATCH supports binary search for better performance on large sorted datasets. The syntax is also cleaner — exact match needs only two arguments instead of three.
  • What is the difference between XMATCH and XLOOKUP?+
    XLOOKUP returns a value directly — you give it a lookup value and it returns the matching item from a return range. XMATCH returns a position number — where the match was found. Use XLOOKUP for straightforward lookups where you want the result directly. Use XMATCH with INDEX when you need the position itself for further calculations, or when you want a two-way lookup that combines row and column positions.
  • Which Excel versions support XMATCH?+
    XMATCH is available in Microsoft 365 (all plans), Excel 2024, and Excel 2021. It is not available in Excel 2019, 2016, or any earlier version. For workbooks that need to open in older Excel, use the MATCH function instead — the results are identical for exact match scenarios, though MATCH requires an explicit 0 as the third argument.
  • How do I use XMATCH to find the last occurrence of a value?+
    Set search_mode to -1: =XMATCH(value, range, 0, -1). The 0 keeps exact match mode, and -1 instructs XMATCH to search from the last item upward. The result is the position of the last occurrence. Combine with INDEX to retrieve the corresponding value: =INDEX(return_range, XMATCH(value, lookup_range, 0, -1)).
  • Should I replace all my MATCH formulas with XMATCH?+
    For new formulas in Excel 365 or 2021, yes — XMATCH is cleaner, safer, and more capable. Do not automatically convert working MATCH formulas in existing spreadsheets unless you have a specific reason to, and never convert formulas in files shared with colleagues on Excel 2019 or older, since XMATCH will return a #NAME? error in those versions.