Determining when data should be aggregated
Now that we know what data we want to aggregate, when should this aggregation be performed? The aggregation should occur once you have identified the level of granularity you require. So, what does the level of granularity mean? It refers to the level of detail that an aggregation is completed to; for example, you want to know your profits at a daily level or monthly level. Other examples include aggregating to the day, month, year, store location, product, and so on.
Going back to Figure 2.1, we have the aggregations based on the invoice date, but we really want to know the totals based on the year, so you would then want to perform the aggregation based on the created dataset. Refer to the following query for how to do this:
SELECT YEAR([Invoice Date Key]) as Year
     Â
,SUM([Quantity]) as "# of items sold"
      ,SUM([Profit]) as profit
    ...