Search code examples
arraysgoogle-sheetsgoogle-sheets-formulagoogle-sheets-querygoogle-query-language

Google Query Return Top N results per category


I have a Google Spreadsheet with several tabs (same columns, split up based on country)

https://docs.google.com/spreadsheets/d/1I4cS4oNjCFZ7dWF78rBv6cdHkyWHAF8rGoIlt0941aI/edit?usp=sharing

I need to have this data copied to my "Master" sheet where I will return the 3 LATEST entries per country.

I have tried to head down the QUERY/IMPORTRANGE path, but I am stuck at the part where I need to return the latest 3 entries per country. Googling around, I could find mentions of the PARTITION BY clause...but unfortunately Google doesn't allow for its use.


Solution

  • try:

    =QUERY({
     QUERY(GB!A:G, "offset "&COUNTA(GB!A:A)-4, 1);
     QUERY(FR!A:G, "offset "&COUNTA(FR!A:A)-3, 0);
     QUERY(IT!A:G, "offset "&COUNTA(IT!A:A)-3, 0);
     QUERY(DE!A:G, "offset "&COUNTA(DE!A:A)-3, 0)},
     "where Col1 is not null", 1)
    

    0