Skip to content

Grouping Tables (Multi to Single row)

This page shows how to group a table so that values spread over several rows end up together in a single cell.

The data has one row per car, so a person who owns three cars appears on three rows:

An Excel table with Person and Car columns, where Ralf, Timothy, Susan and Pamela each have two cars and Richard has three

The aim is one row per person, with all of that person’s cars listed in one cell.

Load the table into Power Query, where it looks like this:

The same Person and Car data in the Power Query editor, with both columns typed as text

Select the Person column and click Group By. Leave the dialog on Basic, grouping by Person with the default Count Rows output:

The Group By dialog in Basic mode, grouping by Person, with one output called Count using Count Rows

The result has one row per person, with a count of their cars:

The grouped query with Person and Count columns, where Richard has a count of 3 and everyone else 2

The Group By dialog has no operation that joins text, so the step’s code needs editing. Select the Grouped Rows step and replace its formula in the formula bar with this:

= Table.Group(#"Changed Type", {"Person"}, {{"Cars", each Text.Combine(List.Sort(_[Car], Order.Ascending), ", "), type text}})

For each person, _[Car] is the list of that person’s cars. List.Sort puts the list in alphabetical order, and Text.Combine joins it into one piece of text, with a comma and a space between the names.

The Cars column now lists each person’s cars in alphabetical order:

The query with Person and Cars columns, where Richard’s cars read Ford, Honda, Lambourghini

Click Close & Load to return the result to the worksheet.