The answer is to use a pivot table, or if you are feeling brave

, then use array formulas.
Array formulas can basically be used like a Sumif function but with multiple conditions. A good article is located
here
Pivot tables are difficult to use in further calculations, and can be both unpredictable and buggy. Array formulas are fast to calculate and can be used in further calculations, but can start to do your head in while you are setting them up.