Hi Dmitri,
Whatever solution you chose, you will need some way to store the totals in order to display on the page, since Mendix doesn’t have the concept of “Variables” so far.
Best solution is to create a two non-persistent entities one YearlyTotals with attributes Year and Cost and another one CategoryTotal with attributes Category and Cost
You can easily aggregate the sum in single step through OQL and assign to the two lists and pass the two lists to two different listviews on the page.
-Shekhar