Search code examples
google-sheetsgoogle-query-language

List Max Date for duplicate rows in a Column - Google Query


I have a data range imported from another sheet that contains an ID, Name & StartDate Columns: e.g.

+------+------+-------------+
| ID   | Name | StartDate   |
+------+------+-------------+
| 1001 | abc  | 11/10/2020  |
+------+------+-------------+
| 1001 | def  | 12/12/2020  |
+------+------+-------------+
| 1002 | ghi  | 04/06/2020  |
+------+------+-------------+
| 1003 | jkl  | 11/08/2020  |
+------+------+-------------+
| 1003 | mno  | 06/02/2020  |
+------+------+-------------+
| 1004 | pqr  | 11/02/2020  |
+------+------+-------------+
| 1004 | stu  | 11/21/2020  |
+------+------+-------------+

into

+------+------+-------------+
| ID   | Name | StartDate   |
+------+------+-------------+
| 1001 | def  | 12/12/2020  |
+------+------+-------------+
| 1002 | ghi  | 04/06/2020  |
+------+------+-------------+
| 1003 | jkl  | 11/08/2020  |
+------+------+-------------+
| 1004 | stu  | 11/21/2020  |
+------+------+-------------+

and i want to find the maximum date for any duplicate ID rows and list the corresponding Name and max StartDate, how is this possible in Google Query?

tried:

=QUERY(J:L,"select J,K,MAX(L) where J is not null group by J,K label MAX(L)'StartDate'")

but still get duplicates i.e. same range.


Solution

  • use:

    =SORTN(SORT(A2:C, 3, ), 9^9, 2, 1, 1)
    

    enter image description here