Summarize grouping by year and month

Solution 1:

This is what pivot tables are for.

I have created an example using your data.

First, add a column to format the date as your monthly string, eg "2009-01" with the formula:

TEXT(A2, "YYYY-MM")

enter image description here


Then highlight the data, and choose "data" > "pivot table report..."

enter image description here


For Rows, select "month"

enter image description here


For Values, select "amount"

enter image description here


TADA! That's it!

enter image description here

For a quick overview of pivot tables, see this Google blog post.

Solution 2:

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))