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 Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

How to Extract Numbers from Text in Excel with Regex

You can use the REGEXEXTRACT or REGEXREPLACE functions to easily extract numbers from text...

Using OFFSET and MATCH Together in Google Sheets: Advanced Tips

One powerful and flexible way to look up values is by combining the OFFSET...

How to Use OFFSET and XMATCH Functions Together in Excel

We often use the OFFSET and XMATCH functions together to match a value in...

How to Calculate Maximum Drawdown in Excel and Google Sheets

You can use the following dynamic array formula to calculate maximum drawdown (MDD) in...

More like this

Using OFFSET and MATCH Together in Google Sheets: Advanced Tips

One powerful and flexible way to look up values is by combining the OFFSET...

Running Count with Structured References in Google Sheets

Running a count with structured references is achievable in Google Sheets tables using the...

Running Total with Structured Table References in Google Sheets

You can use two types of formulas to create a running total with structured...

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.