when i am running a report it first have to filter the records based on month and then for each month group prints the total

For this what code i have to write and on what trigger,

first it have to be filter the Records based on month

and then calculate the amount for the every month group,

something like below?

http://mibuso.com/blogs/mohana/2011/02/11/monthly-purchase-invoices-in-chart/