Power BI Tutorial: Group by Multiple Columns in Power Query

User Question

How can I aggregate sales data by both product category and sales region in Power Query? I need to calculate total sales and average unit price for each combination of these two columns.

Aggregate data by multiple columns in Power BI

Grouping by multiple columns in Power Query allows you to analyze data across various dimensions simultaneously. This technique is particularly useful for creating summary tables that provide insights into complex business scenarios.

For this tutorial, we’ll assume a sales data model with a single table named “Sales” containing the following columns: Date (Date), ProductID (Text), ProductCategory (Text), SalesRegion (Text), UnitsSold (Whole Number), UnitPrice (Currency), and TotalSale (Currency).

Validate grouped results against the source grain

For Power Query grouping, begin with the smallest reproducible example. Note the time and exact action, remove unrelated variables, and change only one factor between tests so a temporary improvement is not mistaken for a fix.

Check the smallest reproducible case

Use Advanced Group By to select each key column explicitly and name every aggregation for its business meaning. Set types and normalize text before grouping so spaces, case differences, or mixed dates do not create unexpected groups.

Keep an All Rows aggregation temporarily when you need to inspect members of each group. Confirm whether null keys belong together and whether Sum, Average, Count Rows, or Count Distinct matches the requested metric.

Validate before closing

Compare the grouped total with the source total and inspect groups containing duplicates, nulls, and one record. Refresh with new categories to ensure the query remains stable and document the intended grain beside the step.

If the result differs by user, network, or device, record that boundary. It helps support teams decide whether the remedy belongs in the profile, endpoint, tenant, or connected service.

Keep the confirmed working setting and note why it was chosen. If the issue returns, the recorded control test provides a safe starting point instead of repeating every possible repair.

When the workflow touches cloud content, verify both the visible item and its underlying storage or permission. A client can display an old reference even when the file, task, recording, credential, or indexed source is unavailable. Confirm ownership and access from the authoritative location.

When documentation differs from the interface, verify product edition, update channel, license, and rollout status. Do not invent a missing menu path; record what is visible and use the current vendor guidance for that exact environment.

If the case affects business records or shared access, have the content owner confirm completeness and permissions. Technical success alone is insufficient when users can open the wrong version or see more information than intended.

Step-by-Step Instructions

  1. First off, open Power BI Desktop and load your data.
  2. Go to Home > Transform data to open the Power Query Editor. Here’s the data i will be using in this example:
  1. Select the “Sales” table in the Queries pane.
  2. From the Transform tab of the ribbon click the “Group By” button.
  3. In the Group By dialog:
  • Select “Advanced” mode.
  • Group by add both ProductCategory and SalesRegion columns.
  • Under “New column name,” enter “TotalSales” and choose Sum as the Operation, selecting the TotalSale column.
  • Click “Add aggregation” and create another column named “AvgUnitPrice” with the Average operation on the UnitPrice column.
  1. Last step would be to click OK to apply the grouping.

DAX Formulas

While this solution primarily uses Power Query, you might want to create additional measures in your report as needed. Here are some relevant DAX formulas you could use:

Total Sales = SUM(Sales[TotalSales])
Average Unit Price = AVERAGE(Sales[AvgUnitPrice])

Key Concepts

  • Grouping by multiple columns creates a unique combination of those columns’ values.
  • Any aggregations are performed within each group, allowing for multi-dimensional analysis.
  • This technique reduces data granularity, summarizing detailed information into a more manageable form.

Some Troubleshooting

  1. Ensure your original data doesn’t contain duplicates that could skew aggregations.
  2. If certain category-region pairs don’t appear, they might not exist in your data. Consider using a full outer join with a separate table of all possible combinations if needed.
  3. Blank values: Handle null or blank values in your grouping columns before applying the Group By operation to avoid unintended results.