google-sheetsgoogle-sheets-formulagoogle-query-language

Using google sheets query functions to filter a list for unique values


I am trying to organize an inventory sheet but need some advice. I have a webhook sending data in regularly. The sheet is below. In the source database, I will update different data fields and then the webhook sends the record (including any changes) along with a timestamp.

I'm trying to return the full row, for only the most recent entry (based on timestamp_incoming_webhook) and filtered for duplicates based on data_inventory_item_serial_number. I am struggling to do this with the query function in a single (or a series of) command(s).

For example, I can do

=query(FilterToAntibodyFlow!A:I, "select A,B,D,E,F,G,H,I,max(C) WHERE B <> '' group by A,B,D,E,F,G,H,I label max(C)'timestamp_incoming_webhook'",1)

but this no longer properly filter for duplicates in the column B (data_inventory_item_serial_number). For example, rows 5 and 6 are duplicates.

screenshot of the output of the query function

But if I only do group by B then the filtering is accurate but I don't get back the other columns of data. How can I get the full record for the most recently changed version?


Solution

  • You may try:

    =let(Σ,reduce(FilterToAntibodyFlow!A1:I1,unique(tocol(FilterToAntibodyFlow!B2:B,1)),lambda(a,c,vstack(a,chooserows(sort(filter(FilterToAntibodyFlow!A:I,FilterToAntibodyFlow!B:B=c),3,),1)))),
     choosecols(Σ,1,2,4,5,6,7,8,9,3))
    

    enter image description here