How to Use VLOOKUP on Duplicates in Google Sheets

This tutorial will guide you on how to effectively use VLOOKUP on duplicates in Google Sheets.

When the search column (the first column in your data range) contains duplicates, using VLOOKUP in its default form will only return the value of the first match.

Let’s examine this with an example where the search key is in cell D2, and the data range is A2:B.

Examples of VLOOKUP on Duplicates in Google Sheets

If you use the standard VLOOKUP formula as shown below, it will only return “Black” (the value from the second column of the first occurrence of the search key):

=VLOOKUP(D2, $A$2:$B, 2, FALSE)

In this case, the search key “Car” appears twice in the first column. If you want to retrieve values from the second column corresponding to both occurrences, you need alternative methods.

Using VLOOKUP on Duplicate Values in Google Sheets

If the VLOOKUP search column contains duplicates, the default function searches for the first occurrence of the search key and returns its corresponding value. To handle duplicates, you have two options:

  1. Retrieve all duplicate values from the first column and their corresponding values from the second column.
  2. Return values from specific duplicate occurrences (e.g., 1st, 2nd, etc.) from the first column.

In this tutorial, we will focus on the first option—how to use VLOOKUP to handle all duplicates. For retrieving specific occurrences, refer to VLOOKUP to Find Nth Occurrence in Google Sheets.

There are two primary methods:

  1. Using the FILTER Function
  2. Using VLOOKUP with an Array Formula

Using the FILTER Function as an Alternative to VLOOKUP

To get started, use the sample data mentioned earlier (A2:B) and apply the following FILTER formula:

=FILTER($B$2:$B, $A$2:$A=D2)

This formula filters column B based on rows where column A equals the search key “Car.” The output will include multiple rows. To display the results in a single row, wrap the formula with TRANSPOSE:

=TRANSPOSE(FILTER($B$2:$B, $A$2:$A=D2))

Place this formula in cell E2. To repeat the lookup for additional search keys, drag the fill handle down.

Filter formula replacing VLOOKUP formula in Google Sheets

For a more efficient solution, you can use a custom LAMBDA function with the MAP helper function:

=MAP(D2:D5, LAMBDA(search_key, TRANSPOSE(FILTER($B$2:$B, $A$2:$A=search_key))))

This formula applies the FILTER logic to each search key in the range D2:D5. It’s a scalable way to perform VLOOKUP on duplicates with multiple search keys.

Using VLOOKUP on Duplicates with an Array Formula

If you need to perform VLOOKUP on duplicates for large datasets, the FILTER method may slow down your sheet. In such cases, you can use an array formula as an alternative.

Consider the following steps:

Create a pivot-like structure where duplicate values in the first column are merged, and their corresponding values occupy separate columns. Here’s how:

=ARRAYFORMULA(QUERY(QUERY({A2:B, COUNTIFS(A2:A, A2:A, ROW(A2:A), "<="&ROW(A2:A))},
"SELECT Col1, MAX(Col2) WHERE Col1 IS NOT NULL GROUP BY Col1 PIVOT Col3"),
"SELECT * OFFSET 1", 0))
Move duplicate values to new columns for VLOOKUP

This formula creates a structured table where each unique key appears once, with its corresponding values arranged in separate columns.

Use this table as the range in your VLOOKUP formula:

=ARRAYFORMULA(IFERROR(VLOOKUP(D2:D5, QUERY(QUERY({A2:B, COUNTIFS(A2:A, A2:A, ROW(A2:A), "<="&ROW(A2:A))},
"SELECT Col1, MAX(Col2) WHERE Col1 IS NOT NULL GROUP BY Col1 PIVOT Col3"),
"SELECT * OFFSET 1", 0), {2,3,4,5}, FALSE)))

This formula retrieves all values corresponding to duplicates for each search key in D2:D5.

Vlookup on duplicate values using virtual range

Note that {2,3,4,5} specifies the index numbers in VLOOKUP to return values from the 2nd to the 5th columns. The first column is omitted because it is the search key column. You can modify this array to include more columns if needed, such as {2,3,4,5,6,7,8,9,10}.

Conclusion

That’s it! You’ve learned two effective methods to handle duplicates using VLOOKUP in Google Sheets. Depending on your data size and requirements, you can choose either the FILTER method or the array formula.

Enjoy working with your data, and check out these additional resources:

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Expert Prashanth KV is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Google Sheets Reading List Tracker Template (Free Download)

Looking for a smarter, more visual way to manage your reading goals? This Google...

Custom Order for QUERY Pivot Headers in Google Sheets

By default, when you use the PIVOT clause in a Google Sheets QUERY, the...

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

Mode of Comma-Separated Numbers in Excel (Dynamic Array)

There is no dedicated function in Excel to directly find the mode of comma-separated...

More like this

Google Sheets Reading List Tracker Template (Free Download)

Looking for a smarter, more visual way to manage your reading goals? This Google...

Custom Order for QUERY Pivot Headers in Google Sheets

By default, when you use the PIVOT clause in a Google Sheets QUERY, the...

Calculate Trip Days by Month (Start, End, and Full Days) in Google Sheets

If you're managing business travel in Google Sheets, you may need to calculate how...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.