Everyone Talks About Aggregation and I'm Too Afraid to Ask

Aggregating (called Grouping in Power Query) takes a selection of categories, and outputs data for which the granularity is set using only those selected categories. This means if there are any repeated rows among those selected categories, aggregating will collapse them into one row - with some prescribed logic for how to collapse numeric fields together. This means aggregation can only remove records (rows).

Think of the categories that you want to "keep", and then understand that if you were to remove the other categories, sometimes you will have repeats among the categories which you chose to keep - which will collapse together after an aggregation step. Sometimes it is helpful to think about just the categories you want to "get rid of", and add all of the other categories into your aggregation step.

Since you are combining records in aggregation, you need to choose how you would like to combine measures (numerical fields), this can be by summing, averaging, counting, etc. This needs to be chosen suitably on a case-by-case basis.



Example 1: Total sales

Consider the following sample of data (out of 5k rows):

To easily see total sales by country, we can use an aggregate step! Add country into Grouped Fields, and Sales in the Aggregated fields using SUM to see the total sales:


Example 2: Collapsing badly formatted rows with aggregation (in Tableau Prep)

In the following, the rows are needlessly separated:

We can fix this by adding an aggregation step that may look useless, but solves our issues! Add all of the categories to Grouped Fields, and all of the measures into Aggregated fields.

Here is the output:

Similar to the above example, aggregation can be used to remove duplicates by adding all of your categories into it - even though it might look silly, an aggregation step like this will collapse any repeats among the categories!

Author:
Jeffrey Brian Thompson
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2024 The Information Lab