Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel XLOOKUP Duplicate Values: How to Find All Matches

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

By default, Excel's XLOOKUP function only returns the first match it finds in a range. To handle duplicate values, you must either change the search mode to find the last occurrence or combine XLOOKUP with the FILTER function to return every matching instance. While XLOOKUP is designed to find a single specific value, understanding how to manipulate its search direction and integrating it with dynamic array functions allows you to manage datasets where a single lookup value appears multiple times.

What You'll Need

  • Microsoft 365 or Excel 2021 (XLOOKUP and FILTER are not available in older versions like Excel 2016 or 2019).
  • A dataset containing a lookup column with duplicate entries (e.g., a list of orders where one customer has placed multiple purchases).
  • A basic understanding of cell referencing and range selection.

Step-by-Step

Depending on your goal, there are three primary ways to handle duplicates. Follow the section that matches your specific requirement.

Method 1: Find the First Occurrence (Default)

  1. Select the cell where you want the result to appear.
  2. Type =XLOOKUP(.
  3. Click the cell containing the value you are searching for (the lookup_value).
  4. Type a comma, then highlight the column or range where the duplicates exist (the lookup_array).
  5. Type a comma, then highlight the column containing the data you want to retrieve (the return_array).
  6. Close the parentheses ) and press Enter.
  7. Excel will scan from the top down and return the very first match it encounters, ignoring all subsequent duplicates.

Method 2: Find the Last Occurrence

  1. Select the cell for your result.
  2. Type =XLOOKUP(.
  3. Input your lookup_value, followed by a comma.
  4. Input your lookup_array, followed by a comma.
  5. Input your return_array, followed by a comma.
  6. To handle duplicates by finding the most recent or last entry, you must fill in the optional arguments. Type 0 for the if_not_found argument, then another comma.
  7. Type 0 for the match_mode (exact match), then another comma.
  8. Type -1 for the search_mode. This tells Excel to search from the bottom of the list upward.
  9. Close the parentheses ) and press Enter.

Method 3: Retrieve All Duplicate Matches (The FILTER Method)

Because XLOOKUP is mathematically designed to return a single value, it cannot "spill" multiple results into different cells on its own. To see every duplicate, you must use the FILTER function.

  1. Select an empty area of your sheet with enough room below and to the right for multiple results to appear.
  2. Type =FILTER(.
  3. Select the return_array (the range of data you want to see). Type a comma.
  4. Select the lookup_array (the column containing the duplicates).
  5. Type = followed by the cell reference of your lookup_value.
  6. Close the parentheses ) and press Enter.
  7. Excel will now create a dynamic array, listing every single row that matches your criteria.

Common Mistakes

One of the most frequent errors is attempting to use XLOOKUP to return a list of values without using the FILTER function. Users often expect that if they select a large return array, XLOOKUP will automatically list all matches; however, XLOOKUP will only ever return one row or one column corresponding to a single match. If you need a list, you must switch functions.

Another common mistake is forgetting the optional arguments when trying to find the last duplicate. If you simply write =XLOOKUP(A2, B:B, C:C), Excel defaults to a search mode of 1 (first-to-last). To reach the search_mode argument (the 6th part of the formula), you must provide values for the 4th and 5th arguments, even if they are just 0 or empty strings. Skipping these will result in a formula error or the wrong result.

Users also frequently confuse the lookup_array and the return_array. The lookup array is where Excel searches for the key; the return array is where the answer lives. Swapping these will result in an #N/A error because Excel cannot find your search term in the data column.

Tips

To make your duplicate lookups more robust, convert your data range into an official Excel Table (Ctrl + T). When you use Table References (e.g., Table1[CustomerName]) instead of cell ranges (e.g., A2:A500), your XLOOKUP and FILTER formulas will automatically update when you add new rows of data. This prevents the common issue where new duplicates are added to the bottom of a list but fall outside the range specified in the formula.

If you are using the FILTER method to handle duplicates and want the results sorted (for example, by date), wrap the entire formula in a SORT function. For example: =SORT(FILTER(ReturnRange, LookupRange=Value), 1, 1). This ensures that your list of duplicates is organized logically rather than appearing in the random order they were entered into the source sheet.

When dealing with very large datasets, avoid referencing entire columns (like A:A). While XLOOKUP is more efficient than VLOOKUP, referencing a million rows can still slow down your workbook. Use Table references or defined Named Ranges to keep the calculation speed high.

Troubleshooting

If your XLOOKUP is returning the wrong duplicate or an error, follow these steps in order:

  1. Check for Hidden Spaces: Often, values that look like duplicates are not identical because one has a trailing space (e.g., "Apple" vs "Apple "). Use the =TRIM() function on your data to remove these invisible characters.
  2. Verify Data Types: Ensure both the lookup value and the lookup array are the same format. If one is stored as Text and the other as a Number, XLOOKUP will not find the match, even if they look identical. You can fix this by using the Text-to-Columns tool to convert the column to the correct format.
  3. Confirm Formula Syntax: If you are trying to find the last occurrence and getting an error, check your commas. Remember that the search mode is the 6th argument. Your formula should look like this: =XLOOKUP(value, lookup_range, return_range, "Not Found", 0, -1).
  4. Check for #SPILL! Errors: If you are using the FILTER function to find all duplicates and see a #SPILL! error, it means there is existing data in the cells where Excel is trying to place the results. Clear the cells below and to the right of your formula to give the dynamic array room to expand.
  5. Update Excel: If the XLOOKUP or FILTER functions do not appear in your formula list, you are likely using an older version of Excel. These functions are not available in Excel 2019 or earlier. You will need to use a combination of INDEX and MATCH for the first/last match, or a complex array formula for all matches.

Frequently Asked Questions

Can XLOOKUP return multiple cells for one match?

XLOOKUP can return a range of cells (a whole row or column) for a single match, but it cannot return multiple different rows that all match the same criteria. For that, you must use the FILTER function.

How do I find the second or third occurrence of a duplicate?

XLOOKUP cannot natively find the "second" match. To achieve this, you would need to create a helper column that assigns a unique ID to each duplicate (e.g., "Customer1-1", "Customer1-2") and then perform an XLOOKUP on that unique ID.

Is XLOOKUP faster than VLOOKUP for duplicates?

Generally, yes. XLOOKUP is more efficient because it doesn't require you to load the entire table array into memory, only the specific columns needed for the search and the return value.

What happens if XLOOKUP finds no matches?

If no match is found, XLOOKUP returns #N/A by default. However, you can customize this by using the 4th argument (if_not_found), such as =XLOOKUP(A2, B:B, C:C, "No Match Found").

Does the order of data affect XLOOKUP duplicates?

Yes. Because XLOOKUP searches linearly, the result depends on the search mode. Search mode 1 finds the first instance from the top; search mode -1 finds the first instance from the bottom.