New Tool Radar

AI for Data & Spreadsheets

How to Summarise a Table by Group With Group By in Power Query

Group a table by region or category in Power Query, sum each group, and check the group totals add up to the source total.

Schematic with three steps: Open Group By and pick the key; Load the summary and check the group; Check the row count per group.

Home, Group By collapses rows with the same key into one row each, with a sum, count or average per group. It is the Power Query way to build a summary table that refreshes with the data, and the group totals must add up to the source total.

What you need

  • Excel with the data loaded in the Power Query Editor
  • A note of the grouping key and the measure to sum
  • The source total, worked out before grouping

Step 1: Open Group By and pick the key

Choose Home, Group By, pick the column to group by, such as Region, and add an aggregation, such as Sum of Amount. You can add several aggregations in one step.

Step 2: Load the summary and check the group totals

Close and Load the grouped table, then add the group totals together. The sum of the groups must equal the source total; if it does not, a row was lost or double-counted.

Step 3: Check the row count per group

Compare the row count of each group with a count from the source. A group with fewer rows than expected usually means a key value with a trailing space split the group in two.

Worked example: synthetic sales by region

The table below is a synthetic example. It shows the expected result of grouping by region; no file was imported.

Region Rows Total
North 12 400
South 10 350
East 8 250
All regions 30 1,000

Expected result (UNTESTED). North 400, South 350 and East 250 add up to 1,000 across 30 rows, which matches the source total. The grouped summary is sound. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Group before merging where it makes sense; joining smaller tables is faster.
  • A key with a trailing space creates a separate group; trim the key column first.
  • Text amounts are skipped by a sum, so check the types before grouping.

Sources

See all