How to merge duplicate rows and sum
Tutor 5 (91 Reviews)
Excel Tutor
Still stuck with a Excel question
Ask this expertAnswer
Merging duplicate rows in Excel involves combining data from rows that share the same key or identifier. This process can consolidate information efficiently without losing data.
Step 1: Identify Duplicate Rows
Select the range of data you want to check for duplicates.
Go to the Home tab.
Click Conditional Formatting → Highlight Cells Rules → Duplicate Values.
Choose a formatting style to highlight duplicates.
Duplicate rows will now be visually marked, making them easier to identify.
Step 2: Remove Exact Duplicate Rows (Optional)
To remove completely identical rows:
Select your data range.
Go to the Data tab.
Click Remove Duplicates.
In the dialog box, select columns to consider for duplicates.
Click OK.
Excel will keep the first occurrence and remove the rest.
Step 3: Merge Data from Duplicate Rows
Merging duplicates often requires combining data from other columns. This can be done using formulas or Power Query.
Option 1: Using Formulas
Suppose column A has duplicate IDs, and column B has values to combine. Use the TEXTJOIN formula:
=TEXTJOIN(", ", TRUE, IF($A$2:$A$100=A2, $B$2:$B$100, ""))
Enter this formula in a new column.
Press Ctrl+Shift+Enter on Windows or Command+Return on Mac if using an array formula version of Excel.
This will concatenate all values from column B for each duplicate in column A, separated by a comma.
Option 2: Using Power Query
Power Query provides a dynamic way to merge duplicate rows:
Select your data range.
Go to Data → Get & Transform Data → From Table/Range.
In Power Query Editor:
Select the column with duplicates.
Click Group By.
Choose All Rows or Concatenate for other columns.
Click Close & Load to return the merged data to Excel.
Power Query ensures changes in the source data automatically update merged results.
Step 4: Verify and Clean Up
Check the merged rows to ensure all relevant data is included.
Delete unnecessary intermediate columns if formulas were used.
Save the workbook to preserve changes.
Example Scenario
A sales table has duplicate Customer IDs:
| CustomerID | Product | Amount |
|---|---|---|
| 101 | Pen | 5 |
| 101 | Notebook | 3 |
| 102 | Eraser | 2 |
Using TEXTJOIN on the Product column:
| CustomerID | Products |
|---|---|
| 101 | Pen, Notebook |
| 102 | Eraser |
This approach keeps all product information for each customer without creating extra rows.
Merging duplicate rows reduces redundancy, improves clarity, and ensures consolidated reporting.
Get Online Tutoring or Questions answered by Experts.
You can post a question for a tutor or set up a tutoring session
Answers · 1
What is the formula to highlight duplicate values
Answers · 1
What is the formula to remove duplicates
Answers · 1
How to delete duplicate values in excel
Answers · 1
How to delete duplicate rows based on one column
Answers · 1