Search code examples
google-sheetsspreadsheet

How to extract Google Sheets data, aggregated by month, grouped by cell value?


A continuation of this thread regarding extracting Google Sheets data aggregated by month, I need to group these flatten/filter/arrayformula results by the values in Col A.

Here's the full Google Sheet - https://docs.google.com/spreadsheets/d/1B_Nzu8iyI1t5zEk9UNmwvS_GKKINdWghlH9HIl9Ppuc/edit?usp=sharing

Background:

I need to automatically keep a running tally of all dollar amounts by month, grouped by Name in Column A.

On the "Commission By Month" tab, I need to see Rep Name filled in, with the corresponding dates and amount values populated correctly.

Currently the "Rep Name" values don’t do anything. They’re only there to demonstrate my desired end-state.

I’ve been trying to group the flatten/filter/arrayformula in Cols B & C, but with no success.

Note: The layout of the original table is not editable, so I can’t align or order the months.


Solution

  • You may try:

    =let(rep_,Deals!A7:A, date_,Deals!J7:AA, size_,2,
         Σ,reduce(tocol(,1),sequence(columns(date_)/size_,1,1,size_),lambda(a,c,vstack(a,{rep_,choosecols(date_,sequence(size_,1,c))}))),
         query(hstack(index(Σ,,1),let(Λ,index(Σ,,2),index(if(len(Λ),eomonth(Λ,-1)+1,))),index(Σ,,3)),"select Col1,Col2,sum(Col3) Where Col1 is not null group by Col1,Col2 order by Col1,Col2  label sum(Col3) ''"))
    

    enter image description here