See two methods:
1) PivotTable Method, 2) Array Formula Method.
The PivotTable Method is the easy way to accomplish this. The Array Formula method is a difficult Array Formula, but it can make all calculations in a single cell and will update instantly if source data changes. For this array formula you will learn some important concepts for Function Argument Array Operations and how to create a rectangular resultant array by carefully creating the Array Constants and Resultant Arrays with the correct Array Syntax. Learn that Curly Brackets house the array, Semi-colons represent Rows and Commas represent Columns. See the Excel Spreadsheet Functions: AGGREGATE, SUMIFS and EDATE.