google-sheetsvlookuplookup

Pull most recent data from one Google Sheet to another


I'm trying to pull the latest information from one Google Sheet to another. The Detail sheet has columns GroupID, Name, Record, Invoice, and Date. There are several invoices and sales records for each Group, received on different dates.

Using Group as a unique key, I'd like to pull the most recent sales record as well as the date into a different Google Sheet, though not into the same cell.

Data in the Detail sheet looks like

| GroupID | Name            | Record # | Invoice # | Date     |
| ------- | --------------- | -------- | --------- | -------- |
| 655-006 | John Doe        | 736703   | 1         | 03/31/22 |
| 655-006 | John Doe        | 540454   | 2         | 06/30/22 |
| 655-006 | John Doe        | 195023   | 3         | 09/30/22 |
| 655-006 | John Doe        | 325078   | 4         | 12/31/22 |
| 655-006 | John Doe        | 390165   | 5         | 03/31/23 |
| 655-006 | John Doe        | 416509   | 6         | 06/30/23 |
| 655-006 | John Doe        | 473567   | 7         | 09/30/23 |
| 655-006 | John Doe        | 411553   | 8         | 12/31/23 |
| 655-006 | John Doe        | 532312   | 9         | 03/31/24 |
| 123-002 | Alex Smith      | 438797   | 1         | 07/31/20 |
| 123-002 | Alex Smith      | 190013   | 2         | 08/31/20 |
| 123-002 | Alex Smith      | 314558   | 3         | 09/30/20 |
| 123-003 | Jane Doe        | 663833   | 1         | 10/31/23 |
| 123-003 | Jane Doe        | 630171   | 2         | 11/30/23 |
| 123-003 | Jane Doe        | 951397   | 3         | 12/31/23 |
| 123-003 | Jane Doe        | 445057   | 4         | 01/31/24 |
| 456-001 | Stephen Colbert | 916524   | 1         | 02/28/21 |
| 456-001 | Stephen Colbert | 719932   | 2         | 03/31/21 |
| 456-001 | Stephen Colbert | 852011   | 3         | 04/30/21 |

I've tried using VLOOKUP, LOOKUP, QUERY, FILTER, MAX, SORT, ARRAYFORMULA, and several combinations thereof, but I'm getting results that are only partially correct. Tried solutions below are on the same sheet for ease of reference instead of from Detail to Summary.

VLOOKUP+SORT, for example, will return the last record correctly, but not the most recent date. =VLOOKUP(G3,SORT($A:$E,5,false),5,false)

QUERY will return the correct results, but only for one unique GroupID, not for all of them. =QUERY(A:E, "SELECT E WHERE A = '"&G:G&"'")

LOOKUP worked on one Group's date, but couldn't match the next GroupID key and instead returned the most recent date for an entirely different one. =LOOKUP(G3,A:E,E:E)

The problem has to be the GroupID for at least some of the possible solutions. I have, however, made sure that the information in Group ID is the same in both sheets, not one as a # and the other as text, etc.

Here's a link to what I'm working with and some examples of what I've tried so far. Sales Test Sheet


Solution

  • You may try:

    =map(A2:A,lambda(Σ,if(Σ="",,xlookup(Σ,Detail!A:A,Detail!B:E,,,-1))))
    

    enter image description here