How to Handle Duplicate Values Using XMATCH vs. MATCH in Excel
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.

- 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.
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.
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.
Click on the empty cell where you want the position number to appear.
Type `=XMATCH(lookup_value, lookup_array` into the formula bar, selecting your target value and data range.
Add a comma and type `0` for the third argument to enforce an exact match: `=XMATCH(lookup_value, lookup_array, 0`.
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)`.
Press Enter to retrieve the position of the last duplicate value.

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. Open your dataset: Launch WPS Spreadsheet and open the workbook containing your lookup data.
- 2. Insert the XMATCH function: Click the target cell, type `=XMATCH(`, and select your target value and data array.
- 3. Configure your parameters: Type `0` for an exact match, specify `-1` if you need a reverse search, close the parentheses, and press Enter.

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.




