Summarize grouping by year and month

后端 未结 6 1926
南笙
南笙 2020-12-24 05:32

I have a worksheet Movements with two fields:

mydate      | amount
2009-01-01  | 10.00
2009-01-02  | 13.00
2009-02-01  | 11.00
2009-02-05  | 12.00
2         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-24 05:53

    You can do it with an array formula, i put the formula in A2 and in A1, i put the month number:

    =ARRAYFORMULA(SUMPRODUCT(1*(MONTH(Sheet1!$A$2:$A$6)=A1)*Sheet1!$B$2:$B$6))
    

    See the doc in action in Google Spreadsheet

    [EDIT] If you want both year and month:

    =ARRAYFORMULA(SUMPRODUCT(1*(YEAR(Sheet1!$A$2:$A$8)=A2)*(MONTH(Sheet1!$A$2:$A$8)=B2)*Sheet1!$B$2:$B$8))
    

提交回复
热议问题