Hello! Welcome to our next lesson.
In our previous session, you learned how to create conditional columns to apply business rules and categorize your data—for instance, labeling sales as "High," "Medium," or "Low." This is a crucial step in adding analytical value to raw data.
Now that we have these meaningful categories, the natural next question is: "What can we do with them?" How do we find the total revenue for all "High Value" orders, or count how many transactions occurred in each region? This brings us to the focus of today's lesson.
We will be covering the learning outcome: Group and aggregate data to create summaries. This is one of the most fundamental and powerful operations in data analysis. It's the process of "rolling up" detailed data into a concise summary table, which is essential for creating reports, charts, and dashboards. For the managers in your workshop, this skill is the bridge between a long list of transactions and a clear, high-level business overview.
By the end of this lesson, you will be able to teach your audience how to:
- Understand the purpose and benefits of grouping data.
- Use Power Query's Group By feature to summarize data by one or more columns.
- Apply various aggregation functions like
Sum,Average, andCountto answer specific business questions. - Recognize why grouping data is a critical step for improving report performance.
What are Grouping and Aggregation?
Imagine you have a table with thousands of individual sales records. Trying to find insights by reading through it row-by-row is impossible. Grouping and aggregation is the solution.
- Grouping is the act of creating "buckets" based on the values in one or more columns. For example, you could create a bucket for each
Countryin your dataset. - Aggregation is the calculation you perform on the data within each bucket. For example, you could
SumtheSales Amountfor each country's bucket to get the total sales per country.
Together, they transform a detailed table into a compact summary.

The "Group By" Feature in Power Query
Power Query provides a dedicated, user-friendly feature for this, called Group By. You can find it in a few places in the Power Query Editor, making it easily accessible:
- On the Home tab, in the Transform group.
- On the Transform tab, in the Table group.
- By right-clicking the header of the column(s) you want to group by.
Let's see how it works in practice.
Walkthrough 1: Basic Grouping (by a Single Column)
The simplest use case is grouping by a single category. Let's say your managers want to know the average quantity of each item sold.
This video provides a clear, concise demonstration of this first step.
23 - Group Data in Power Query in Excel
This video, '23 - Group Data in Power Query in Excel' from the TrumpExcel channel, will show you how to perform a basic grouping operation. Pay close attention to the dialog box and how each field is configured.
Watch from 01:03 to 02:47. The presenter demonstrates how to: Select the column to group by (item). Define the new aggregation column (e.g., average). Choose the operation (Average). Select the column to perform the calculation on (quantity).
As you saw, the Group By dialog box neatly separates the grouping logic from the aggregation logic, making it intuitive for beginners.
Walkthrough 2: Advanced Grouping (by Multiple Columns)
Business questions are often more specific. A manager might not just want total sales per country, but total sales per product within each country. This requires grouping by multiple columns. To do this, you use the Advanced option in the Group By dialog.
The official Microsoft documentation provides an excellent text-based walkthrough for this scenario.
How to GROUP BY or summarize rows - Power Query
This article from Microsoft Learn, 'How to GROUP BY or summarize rows', gives a step-by-step guide on using the 'Advanced' grouping feature. This is a great resource to have on hand for your workshop.
Read the section titled 'Use an aggregate function to group by one or more columns'. Follow the 7-step process it outlines for grouping by both 'Country' and 'Sales Channel' to calculate 'Total units'. Notice how the 'Add grouping' button allows you to build more complex summaries.
Why Grouping is Crucial for Performance
Beyond just summarizing data for analysis, grouping has a major technical benefit: performance. This is a key selling point for busy managers who value efficiency.
When you load data into a tool like Power BI, it has to store every single row and column in your computer's memory. A dataset with 10 million rows of individual transactions is massive and will make reports slow and unresponsive.
However, if you first group those 10 million rows into a summary of, say, 500 rows (e.g., total sales per store per day), the resulting dataset is tiny. The report will be incredibly fast.
This video explains the concept perfectly.
GROUP BY in Power BI Query Editor - Do you need all that detail?
The video 'GROUP BY in Power BI Query Editor - Do you need all that detail?' from How to Power BI makes a compelling case for using Group By as a performance optimization tool. This is a powerful message for your workshop audience.
Watch the introduction (00:00 - 00:30) and the section explaining the performance benefits (03:41 - 04:25). The key takeaway is that you should match the level of detail in your data to the level of detail needed for your visuals. Don't load millions of rows if your chart only shows 10 bars.
Test your understanding!
You have a sales dataset with the columns Region, Sales Rep, and Order Amount. Your manager wants a summary table showing the total number of orders and the average order amount for each sales rep within each region.
How would you configure the Group By dialog box to achieve this?
Show answer
You would use the Advanced option in the Group By dialog.
-
Grouping:
- Group by:
Region - Add grouping:
Sales Rep
- Group by:
-
Aggregations:
- Aggregation 1:
- New column name:
Total Orders - Operation:
Count rows - Column: (Not applicable for
Count rows)
- New column name:
- Aggregation 2 (Add aggregation):
- New column name:
Average Order Amount - Operation:
Average - Column:
Order Amount
- New column name:
- Aggregation 1:
This setup first creates buckets for each unique combination of Region and Sales Rep, and then calculates two separate summaries for each bucket.
Exploring Other Aggregation Operations
While Sum is the most common aggregation, Power Query offers a wide range of functions to answer different business questions. It's useful to know the main ones so you can teach your managers how to choose the right one for their needs.
Here is a summary of the most common operations available:
| Operation | Business Question Example |
|---|---|
| Sum | "What are the total sales for each product?" |
| Average | "What is the average customer satisfaction score per store?" |
| Median | "What is the median salary for each job level?" (Good for skewed data) |
| Min / Max | "What was the highest/lowest temperature recorded each day?" |
| Count Rows | "How many transactions did each sales rep make?" |
| Count Distinct Values | "How many unique customers purchased from each region?" |
| All Rows | (Advanced) "For each category, give me a table of all original rows." |
The All Rows operation is a more advanced technique that you can mention as a "power user" feature. It allows for complex calculations, like finding the top-performing product within each category, but is not essential for a beginner workshop.
Conclusion
You now have a solid understanding of how to group and aggregate data in Power Query. This is a fundamental skill that allows managers to move from overwhelming detail to high-level, actionable summaries.
Key Takeaways for Your Workshop:
- Group By is for Summarization: It rolls up detailed data (like transactions) into summaries (like totals per category).
- Two Key Benefits: It answers critical business questions and dramatically improves report performance.
- The Process: Use the Group By dialog to select columns for your "buckets" and then define the calculations (aggregations) to perform on each bucket.
- Choose the Right Operation: Teach managers to think about the question they are asking to select the right function (
Sum,Average,Count, etc.).
Preview of the Next Lesson:
We've now covered several key data transformation steps. However, data from real-world systems often comes in formats that aren't ideal for analysis. A common issue is data presented in a "crosstab" or "pivot" format (e.g., with months or years as columns). In our next lesson, we will tackle this by learning how to unpivot data to transform it into a usable format for analysis, making it ready for creating flexible reports and visuals.