Grouping rows in Power Query can help show your data in a summarized way. You group rows by one or more columns and perform aggregations.
Many times, Excel users need to show their data in a summarized way. Go-to tools for many are PivotTables or formulas as SUMIFS, SUMPRODUCT, AGGREGATE and the like. Yet with Power Query, Excel users now have another tool to summarize their data.
You can find the video tutorial on the beginning of this article. If you would rather read the tutorial or need more instructions, then continue reading.
Importing a Table into Power Query
Above table contains the sales from April 2018. I’m interested in the amount sold per Product. Let’s get started. First of all:
- select a cell within the table
- Next, go to the tab Data -> click From Table/Range
These steps import the table into Power Query so you can work with it.
Grouping or Summarizing Data
The effect of grouping data is that it shows data on a higher (aggregated) level. For our data, I am interested in the sales per Product.
Currently my data contains multiple rows within a single product group. Grouping By Product summarizes these rows into a single grouped row per product.
First of all, to achieve this grouping:
- go to the tab Home -> Group by
In this screen you can select the variable(s) to group your data by. You select Advanced only when you want to group by multiple variables or when you want to perform an operation on more than one variable. In this case you can leave the selection at Basic.
Next, you can choose several options on how to output your data. For this exercise:
- Group your data by ‘ProductDescription’
- Name a column ‘Sales’, and SUM up the column ‘Amount’
- Press “Ok”
The below table is the result of these steps. What’s left is all unique values from the column ProductDescription and a column with the underlying sales values.
To move this data to the worksheet you:
- click on Close & Load -> press Close & Load To…
After, you get a menu to specify how you would like to import the data. In this case:
- Select Table -> click on the Existing Worksheet -> select cell F5
- Click OK
The resulting table is now imported onto the Excel worksheet.
Conclusion
This post showed a very basic Group By operation in Power Query. If you are only interested in the sales per Product you are now done. Yet much more complex options are available for grouping your data.
You can for example use Fuzzy Grouping for grouping items that are similar. And the next post shows how to group your data and get the top seller in Power Query. Please leave a comment below with questions or suggestions. See you next time!
Recommended Reading…
Power Query Foundations
Beginners Guide to Power Query
List Functions (200+ Examples)
Text Functions (150+ Examples)
Creating Tables (40+ Examples)
Generate the Ultimate Date Table
Advanced Topics
Master List.Generate with Easy Examples
Deep Dive into List.Accumulate
Any advice to summarize several columns in bulk?, Iet’s say i have a table with multiple columns ( 10 or more) and i need to get the total sum of each one, with the User Interface i neet to do it one by one. Thanks
Thanks Rick,
Something you shared around grouping of data and adding an index lead to me attempting something in one of my Power BI files.
I have a created groups, added an index and it all seems to be working, but I have a problem. Some of the records for each grouping fall on the same date, which throws the data into the wrong pattern. So I thought, no problem I will sort the table by date and then by another column to get what I need (multiple sort). But the problem is that when I group the data, the sorting disappears…? And when I tried to add ‘table.buffer()’ in a prior step, it completely messes with the result.
Can you advise, how do I sort the columns in a grouping prior to adding an index?
Absolutely.
Imagine you’re grouping your data by Color. The Table.Group function could be something like:
You can also include the sorting and index argument within this:
However, in my experience the Table.Buffer function works fine too. If you first sort your data, then Buffer the result. You can Group the data and my tests so far have shown to give a good result. Some more info on Table.Buffer and its effects you can find here: https://gorilla.bi/power-query/removing-duplicates/