Google Sheets – Group Values by Month and Sum Previous Values

formulasgoogle sheetsgoogle-sheets-arrayformulagoogle-sheets-query

I would like to sum the values ​​of a table grouped by months but adding up the previous months.

Example:

Example

Result that I want:

Result

The closest I've come so far is:

=Query(B2:C4;"select sum(C), B group by B"; -1)

Best Answer

=QUERY({B2:C}; "select Col1,sum(Col2) 
                where Col1 !='' 
                group by Col1 
                label sum(Col2)''"; 0)

0

0


=ARRAYFORMULA({"Month"\ "Total"; {
 QUERY(QUERY({B2:C}; "select toDate(Col1),sum(Col2) 
                      where toDate(Col1) is not null 
                      group by toDate(Col1) 
                      label sum(Col2)'',toDate(Col1)''"; 0); "select Col1"; 0)\ 
 MMULT(TRANSPOSE((ROW(INDIRECT("A1:A"&COUNTA(
 QUERY(QUERY({B2:C}; "select toDate(Col1),sum(Col2) 
                      where toDate(Col1) is not null 
                      group by toDate(Col1) 
                      label sum(Col2)'',toDate(Col1)''"; 0); "select Col2"; 0))))<=
 TRANSPOSE(ROW(INDIRECT("A1:A"&COUNTA(
 QUERY(QUERY({B2:C}; "select toDate(Col1),sum(Col2) 
                      where toDate(Col1) is not null 
                      group by toDate(Col1) 
                      label sum(Col2)'',toDate(Col1)''"; 0); "select Col2"; 0))))))*
 QUERY(QUERY({B2:C}; "select toDate(Col1),sum(Col2) 
                      where toDate(Col1) is not null 
                      group by toDate(Col1) 
                      label sum(Col2)'',toDate(Col1)''"; 0); "select Col2"; 0)); SIGN(
 QUERY(QUERY({B2:C}; "select toDate(Col1),sum(Col2) 
                      where toDate(Col1) is not null 
                      group by toDate(Col1) 
                      label sum(Col2)'',toDate(Col1)''"; 0); "select Col2"; 0)))}})

0