Why don't you just use a pivot table?