Function Problems

How to Handle Duplicate Values Using XMATCH vs. MATCH in Excel

Rana GarciaRana Garcia Oct 29, 2026 869 views

Question details

Understand the differences between XMATCH and MATCH functions when dealing with duplicate values and learn how to use search modes for accurate lookup results.

How to Handle Duplicate Values Using XMATCH vs. MATCH in Excel
Product
Spreadsheet
Device & OS
not provided
Scenario
Looking up the position of a specific item in an array that contains duplicate entries.
Observed behavior
XMATCH and MATCH return different position numbers for the same lookup value because of differences in their default search directions and match behaviors.
Before you start

Verify whether your dataset requires an exact match or an approximate match, and determine if you need to find the first or the last occurrence of the duplicate value.

Solution 1Recommended

Control Search Direction Using the XMATCH Search Mode Argument

Explicitly define the fourth argument in the XMATCH function to specify whether it searches top-to-bottom or bottom-to-top, ensuring the correct duplicate is found.

XMATCH searches downward (first-to-last) by default. If your dataset has duplicate values and you want a result that mirrors a bottom-up MATCH lookup, you must override the default search behavior.

Using the fourth argument (search_mode), you can instruct XMATCH to perform a reverse search, easily grabbing the last occurrence of your lookup value.

1
Select the output cell

Click on the empty cell where you want the position number to appear.

2
Enter the base XMATCH formula

Type `=XMATCH(lookup_value, lookup_array` into the formula bar, selecting your target value and data range.

3
Specify the match mode

Add a comma and type `0` for the third argument to enforce an exact match: `=XMATCH(lookup_value, lookup_array, 0`.

4
Set the search mode to reverse

Add another comma and type `-1` for the fourth argument to search last-to-first (bottom-to-top): `=XMATCH(lookup_value, lookup_array, 0, -1)`.

5
Apply the formula

Press Enter to retrieve the position of the last duplicate value.

Control Search Direction Using the XMATCH Search Mode Argument
Search Mode Options: In XMATCH, a search_mode of 1 searches first-to-last (default), -1 searches last-to-first, 2 performs a binary search (ascending order), and -2 performs a binary search (descending order).
Advanced Spreadsheet Functions

Perform Precise Lookups with WPS Spreadsheet

WPS Spreadsheet fully supports advanced modern functions like XMATCH. Easily handle duplicate data, control search directions, and analyze complex arrays with zero hassle.

  1. 1. Open your dataset: Launch WPS Spreadsheet and open the workbook containing your lookup data.
  2. 2. Insert the XMATCH function: Click the target cell, type `=XMATCH(`, and select your target value and data array.
  3. 3. Configure your parameters: Type `0` for an exact match, specify `-1` if you need a reverse search, close the parentheses, and press Enter.
100% compatibility with Microsoft Excel functions, including XMATCH, MATCH, and XLOOKUP.Free and lightweight software ensuring smooth performance on large datasets.Built-in syntax helpers to guide you through complex formula arguments.
microsoft office alternative - wps office

Frequently Asked Questions

Why does XMATCH return a different position than MATCH for the exact same value?

XMATCH defaults to an exact match and searches from the first item to the last. Older MATCH formulas often default to an approximate match if the match type isn't specified, or may behave differently on unsorted data, causing them to land on different occurrences of duplicates.

How do I make XMATCH search from the bottom up?

You can reverse the search direction by setting the fourth argument (search_mode) of the XMATCH function to -1. The syntax is `=XMATCH(lookup_value, lookup_array, 0, -1)`.

Can I use XMATCH to find every instance of a duplicate value?

No, XMATCH is designed to return only a single position based on your specified search direction (either the first or last occurrence). To retrieve all instances of a duplicate value, you should use the FILTER function instead.