Google-sheets – How to retrieve unique rows by an index column in Google Spreadsheet

google sheets

Suppose I have the following Google Spreadsheet:

id1 mkdmc   cdjnc
id2 cn39    cncn
id3 cndc    cncn
id1 3mc     cm

And I want to transform it into:

id1 mkdmc   cdjnc
id2 cn39    cncn
id3 cndc    cncn

So to remove the row that has a duplicated id1 in column A. Note that the row isn't fully duplicated, just the value in column A.

How would I go about doing this with a formula?

Best Answer

={unique(A:A), arrayformula(vlookup(unique(A:A), A:B, 2, false))}

Explanation:

  • A table of 2 columns is constructed in a single formula (expanding to 3 columns is left as an exercise to the reader)
  • The first column is the list of unique IDs
  • The second column looks up the 1st value by that id in the second column of source