Exclude Duplicate Keys in VLOOKUP Array Result in Google Sheets

How do we assign a VLOOKUP result only to the first occurrence of the search key in a range? This is usually required when using an array formula with VLOOKUP. To exclude duplicate search keys in a VLOOKUP array formula result, we can use an IF logical test combined with a running count.

The logic works as follows: We find the running count of the search keys. If the count is one, we use VLOOKUP to return the result; otherwise, we leave the cell blank.

Although this typically requires an array formula, we will begin with a non-array formula to help you understand the process better.

Example

In the following example, I have search keys in the range A2:A10, which are fruit names, and the lookup table is in the range F2:G6, where the first column contains fruit names and the second column contains their prices.

Looking at the search keys, you can see that some fruits are repeated. I want a VLOOKUP formula in cell B2 that excludes duplicate search keys and returns results only for the first occurrence.

Example of Excluding Duplicate Search Keys in VLOOKUP Array Result

Exclude Duplicate Search Keys in VLOOKUP Using a Drag-Down Formula

As per the example above, you can use the following formula in cell B2 and drag it down:

=IF(
   COUNTIF($A$2:A2, A2)=1,
   VLOOKUP(A2, $F$2:$G$6, 2, FALSE),
)

How does this formula work?

The COUNTIF formula, COUNTIF($A$2:A2, A2), returns the running count of the search key as you drag it down. As you drag the formula down, the range becomes $A$2:A3, $A$2:A4, and so on, with the criterion becoming A3, A4, etc. The formula returns the count of the current item up to that row, which is the running occurrence.

The IF function evaluates whether the COUNTIF result is 1, and if it’s TRUE, it executes the VLOOKUP; otherwise, it returns a blank.

This is how you can exclude duplicate search keys in a VLOOKUP drag-down formula. Now, let’s see how to achieve the same result with a VLOOKUP array formula that expands down from B2.

Exclude Duplicate Search Keys in VLOOKUP Array Formula Result

The formula follows the same logic as above. The difference is that you should specify the search key range A2:A10 in the VLOOKUP instead of just A2. You’ll also need to replace the COUNTIF formula with a COUNTIFS formula. Additionally, the formula must be entered as an array formula.

Empty the range B2:B and insert the following formula in cell B2:

=ArrayFormula(
   IF(
      COUNTIFS(A2:A10, A2:A10, ROW(A2:A10), "<="&ROW(A2:A10))=1, 
      VLOOKUP(A2:A10, F2:G6, 2, FALSE),
  )
)

Here’s how it works:

  • The COUNTIFS(A2:A10, A2:A10, ROW(A2:A10), "<="&ROW(A2:A10)) part returns the running occurrence of the VLOOKUP search keys.
  • The IF function returns TRUE wherever the COUNTIFS result is 1 and executes the VLOOKUP array formula in those rows.

This is how we can exclude duplicate search keys in the VLOOKUP array result in Google Sheets.

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.

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...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

More like this

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...

How to Find Mode of Comma-Separated Numbers in Google Sheets

Working with comma-separated numbers inside a single cell is a common scenario in Google...

How to Count Merged Cells in Google Sheets (and Get Their Size)

Sometimes, you may have blocks of merged cells in a column or row. But...

2 COMMENTS

  1. I am trying to use this with a question bank I have for google forms, but I am not putting in the right info to get it to work. Below is the Vlookup formula I am using, which pulls from another sheet with questions on it. Can you please help me fix this?

    =vlookup(randbetween(1,max(questions!$A:$A)),questions!$A$2:$B,2,false)

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.