google spreadsheet - remove duplicates based on one column and keep last entry -


i'm trying remove duplicates based on 1 column , keep last entry. right formula keeping first value.

i'm using formula found in post: selecting rows distinct column values - google query language

well short answer change 0 (or false) in formula 1 (or true) vlookup matches last entry each unique value

=arrayformula(iferror(vlookup(unique(data!d:d),{data!d:d,data!a:d}, {2,3,4,5},1 ),"")) 

this appear work test data

enter image description here

but isn't end of story.

if use vlookup formula data has sorted on lookup column according documentation in comments above said can't assume data sorted on lookup column. things go horribly wrong if try on unsorted data. have sort on lookup column this

=arrayformula(iferror(vlookup(sort(unique(data1!d2:d),1,true),sort({data1!d2:d,data1!a2:d},1,true), {2,3,4,5},1 ))) 

the slight downside being doesn't include headings (because sorted end of data).

here same test data sorted in descending order on id

enter image description here

this gives correct result (but without headers)

enter image description here

you can add headers putting

=query(data1!a:d,"select * limit 0") 

above data.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -