Group Data and Keep Other Columns in Excel Power Query
Question details
Group records in Power Query while preserving related columns or returning the original rows with maximum values.

- Product
- Microsoft Excel Power Query
- Device & OS
- not provided
- Scenario
- The user wants to calculate sums or maximums by selected keys and retain information from the source records.
- Observed behavior
- The desired result includes group calculations alongside relevant original columns.
Open the query in Power Query Editor and identify the grouping keys, the numeric column to aggregate, and the columns you want to retain. Make sure matching key and value columns use compatible data types.
Merge grouped maximums with the original rows
Use this method to return the source columns for every record that matches its group's maximum value.
In the Queries pane, right-click the query before grouping and select Duplicate. Keep one copy as the original-row query and use the other for grouping.
Select the grouping copy, then choose Home > Group By. Select Advanced, add the required key columns, and create an aggregation with the Max operation on the value column.
Select the grouped query and choose Home > Merge Queries. Choose the original-row query as the second table, not the grouped query itself.
In the merge dialog, select the group keys and maximum column in the grouped table, then select the corresponding keys and value column in the original table in the same order. Use an Inner join and select OK.
Select the expand icon on the merged column and choose the original columns you want to return. Select Home > Close & Load to load the result.

Keep source rows alongside a group total
Use All Rows when you want to calculate a group sum and retain the individual records behind it.
Work with grouped spreadsheet data in WPS Office
WPS Office is a free, lightweight Microsoft Office alternative with a familiar spreadsheet interface and support for common Excel formats, making it easy to move existing files. It does not fix Excel Power Query or replace the merge workflow described above.

Frequently Asked Questions
Why do other columns disappear when I use Group By?
Group By returns the selected keys and aggregation results rather than every source column. Add an All Rows aggregation to retain nested source records, or merge the grouped results with the original query.
How do I return the row with the highest value in each group?
Use Home > Group By to calculate Max for each key, then use Home > Merge Queries to match the grouped keys and maximum value to the original query's keys and value column. Expand the merged column to return the source fields.
What happens if two rows have the same maximum value?
Both rows match the group maximum and are returned by the merge. Apply an additional tie-breaking rule if you need only one row per group.
Can I keep individual rows and show a group sum?
Yes. In Home > Group By, choose Advanced and add both a Sum aggregation and an All Rows aggregation. Expand All Rows to show the original records; the group sum will repeat for each record.




