Power Query Problems

Merge Duplicate Excel IDs and Combine Values on Separate Lines

Steven ParkerSteven Parker Nov 14, 2026 869 views

Question details

Combine rows with duplicate IDs into one row per ID, with related values on separate lines in each column.

Merge Duplicate Excel IDs and Combine Values on Separate Lines
Product
Microsoft Excel Power Query
Device & OS
not provided
Scenario
An Excel table contains repeated IDs and multiple related data columns that need to be consolidated.
Observed behavior
The desired result is one row per ID, with values from each related column separated by line breaks within their respective cells.
Before you start

Make sure the ID is the first column and that at least one related data column follows it. Convert the range to an Excel table and check its name on the Table Design tab; the example below uses Table1.

Solution 1Recommended

Group IDs and combine all related columns with Power Query

Use this refreshable query to process every column after the ID column at once.

The query groups rows by the first column and joins values in each remaining column with a line feed. Blank source cells remain blank lines so that related values retain their positions.

The code uses _MergedData as a temporary column name. If your ID column has that name, rename the ID column before running the query.

1
Create a table

Select the source range, choose Insert > Table, and confirm that your table has headers. On the Table Design tab, name the table Table1 or note its existing name.

2
Open Power Query

Click anywhere in the table and choose Data > From Table/Range to open the Power Query Editor.

3
Replace the query code

In Power Query Editor, choose Home > Advanced Editor. Replace the existing code with the following, changing Table1 if your table has a different name, then select Done: let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], IDColumn = Table.ColumnNames(Source){0}, ValueColumns = List.Skip(Table.ColumnNames(Source), 1), Grouped = Table.Group(Source, {IDColumn}, {{"_MergedData", (t as table) as record => Record.FromList(List.Transform(ValueColumns, (c) => Text.Combine(List.Transform(Table.Column(t, c), (v) => if v = null then "" else Text.From(v)), "#(lf)")), ValueColumns), type record}}), Result = Table.ExpandRecordColumn(Grouped, "_MergedData", ValueColumns, ValueColumns) in Result

4
Load and format the result

Choose Home > Close & Load. In the result table, select the combined-value columns and choose Home > Wrap Text to display each line within its cell; adjust row height if needed.

5
Refresh after changes

After editing or adding rows to the source table, right-click the result table and select Refresh. Newly added columns after the ID column are also included when the query refreshes.

Group IDs and combine all related columns with Power Query
About commas: The query inserts line breaks between values from separate source rows; it does not split commas already inside a source cell. Splitting those commas could disrupt the alignment of related information across columns.
Free Microsoft Office alternative

Work with Excel tables in WPS Spreadsheet

WPS Office is a free, lightweight alternative with a familiar interface and support for Excel files, making it easy to move everyday spreadsheet work between applications. The Power Query steps above must be completed in Excel.

Open and edit tables with repeated IDs in WPS SpreadsheetCompatible with Microsoft Excel XLS and XLSX formatsFamiliar spreadsheet interface for an easier transitionFree and lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Can the query combine all related columns at once?

Yes. The query identifies the first column as the ID and processes every column after it. New columns added after the ID are included when you right-click the result table and select Refresh.

Why do the combined values appear on one line?

Select the result columns and choose Home > Wrap Text in Excel. Increase the row height if the separate lines still are not fully visible.

Will a comma inside a source cell become a line break?

No. The query adds line breaks between values from different source rows. Commas already inside a cell remain unchanged.

What happens to blank values in a duplicate ID group?

A blank source cell becomes a blank line in the combined result. This helps preserve the position of related values across columns.

How do I update the result after adding incidents?

Add the new rows to the source Excel table, then right-click the query's result table and select Refresh.