How to combine duplicate rows in Excel
By the Analistable team · Updated · 2 min read
To combine duplicate rows into one row per value, list the unique values with =UNIQUE(A2:A100) and add them up with =SUMIFS(C:C, A:A, E2) — or use a pivot table. To join the text from duplicate rows instead of adding numbers, use =TEXTJOIN(", ", TRUE, FILTER(B$2:B$100, A$2:A$100=E2)). Power Query Group By does both and refreshes.
Part of our guide: How to compare two spreadsheets for differences and matches
The example
| Customer | Product | Amount |
|---|---|---|
| Bakery Lune | Desk | 120 |
| Hart & Co | Lamp | 40 |
| Bakery Lune | Chair | 80 |
| Nordic Supply | Desk | 75 |
| Hart & Co | Desk | 120 |
| Customer | Products | Total |
|---|---|---|
| Bakery Lune | Desk, Chair | 200 |
| Hart & Co | Lamp, Desk | 160 |
| Nordic Supply | Desk | 75 |
Formulas (Microsoft 365)
- In E2:
=UNIQUE(A2:A6)lists each customer once. - In F2:
=TEXTJOIN(", ", TRUE, FILTER($B$2:$B$6, $A$2:$A$6=E2))joins their products. Fill down. - In G2:
=SUMIFS($C$2:$C$6, $A$2:$A$6, E2)adds their amounts. Fill down.
Newer Microsoft 365 builds also have GROUPBY: =GROUPBY(A2:A6, C2:C6, SUM) returns the customers and totals in one formula.
Pivot table (any version)
Select the data, choose Insert → PivotTable, drag Customer to Rows and Amount to Values. Excel sums duplicates automatically. Pivot tables can't join text, so use TEXTJOIN or Power Query for the Products column.
Power Query Group By (repeatable, text and numbers)
Load the table with Data → From Table/Range, choose Home → Group By, select Advanced, group by Customer and add a Sum of Amount. Then edit the formula bar so the products are joined:
= Table.Group(Source, {"Customer"}, {
{"Products", each Text.Combine([Product], ", "), type text},
{"Total", each List.Sum([Amount]), type number}
})Close & Load. When new orders are added to the source table, click Refresh.
Merge duplicates without losing data
Data → Remove Duplicates keeps the first row of each group and deletes the rest, including any different values in other columns. Combine first with one of the methods above, then remove the originals. To merge two separate lists and drop repeated rows, see merging two spreadsheets and removing duplicates.
Duplicates that look identical but aren't grouped usually differ by a trailing space or capitalisation. Clean the key with =TRIM(PROPER(A2)) first.
Which method should you use?
- Need numbers only, quickly → pivot table.
- Need text and numbers together, live → UNIQUE + TEXTJOIN + SUMIFS (Microsoft 365).
- Same job every month, or large data → Power Query Group By.
- Just need to delete repeats and keep one row → Data → Remove Duplicates, after checking nothing in the other columns differs.
Frequently asked questions
- How do I merge duplicate rows and sum the values in Excel?
- Use a pivot table with the key in Rows and the number in Values, or =UNIQUE() with SUMIFS, or GROUPBY in newer Microsoft 365.
- How do I combine duplicate rows and keep all the text?
- Use =TEXTJOIN(", ", TRUE, FILTER(text_column, key_column=key)) next to a UNIQUE list of keys, or Power Query Group By with Text.Combine.
- Does Remove Duplicates merge rows?
- No. It keeps the first row of each duplicate group and deletes the others, so data in the deleted rows is lost.