Combine Duplicate Rows and Sum Values in Excel

Tested prompts for merge duplicate rows and sum values excel compared across 5 leading AI models.

BEST BY JUDGE SCORE Claude Haiku 4.5 9/10

You have an Excel sheet where the same customer, product, or SKU appears on multiple rows, and you need one clean row per item with the numeric columns added together. Maybe it's a sales export where each transaction got its own line, or a budget file where the same category shows up in fifteen places. You want one row per unique value with the totals summed.

Excel gives you several ways to do this: PivotTables, Consolidate, SUMIF, Power Query, or Remove Duplicates combined with formulas. Each works, but picking the wrong one wastes time or quietly drops data. This page shows a tested AI prompt that decides the right method for your specific sheet and writes the exact steps, formulas, or M code you need.

Below you'll see the prompt, outputs from four different models, and a comparison so you can copy the approach that matches your data shape. If you just need the quick answer: for one-off cleanups use a PivotTable, for repeatable workflows use Power Query's Group By.

When to use this

Use this approach when your sheet has a key column with repeated values and one or more numeric columns you want to total per key. It works for transaction logs, line-item exports from CRMs or ERPs, inventory counts across locations, and survey responses grouped by respondent. The goal is always the same: collapse many rows into one row per unique key.

  • Sales exports where the same customer or product appears across dozens of order lines
  • Expense reports with repeated vendor names that need totaled spend per vendor
  • Inventory sheets with the same SKU tracked across multiple warehouses or dates
  • Time-tracking exports where employees log multiple entries per project
  • Survey or form data where one respondent submitted several partial entries

When this format breaks down

  • Your 'duplicate' rows aren't actually identical in the key column (typos, trailing spaces, or case differences) without cleaning them first
  • You need to keep all original rows for audit purposes and only want a separate summary view, in which case use a PivotTable on the side instead of overwriting data
  • The non-numeric columns have different values per row that you can't just drop (for example, different notes or timestamps that matter)
  • You're working with more than a few hundred thousand rows, where Power Query or a database will outperform worksheet formulas

The prompt we tested

You are an Excel expert helping a user merge duplicate rows and sum their numeric values. Analyze the user's data description or sample below and provide a clear, step-by-step solution.

Instructions: Respond with a numbered step-by-step guide covering the most relevant methods (Consolidate tool, Pivot Table, SUMIF formula, or Power Query) based on the user's data. Include exact menu paths (e.g., Data > Consolidate), sample formulas with placeholder ranges, and briefly note when to use each method. Keep the response practical and under 400 words.

User's data/situation:
I have a sales spreadsheet with about 500 rows in columns A and B. Column A has product names (many repeat) and column B has sales amounts. I want to combine all duplicate product names into one row each and sum their sales totals.

Provide the best method(s) to merge duplicates and sum values, including exact steps, formulas, or Excel features to use.

Model comparison

ModelQualityCostLatencyTokens
Claude Opus 4.7 9 $0.0746 15.2s 317 / 931
Claude Haiku 4.5 9 $0.0034 6.5s 224 / 644
GPT-5.4 9 $0.0753 29.2s 198 / 1833
Gemini 2.5 Pro 9 $0.0022 17.7s 212 / 395
Grok 4.1 Fast Reasoning 9 $0.0003 7.1s 348 / 430

Outputs

Claude Opus 4.7 9/10
# Merging Duplicate Products & Summing Sales in Excel

For 500 rows with product names (Column A) and sales (Column B), here are the three best methods ranked by ease:

## Method 1: Pivot Table (Recommended — Fastest & Cleanest)

1. Click anywhere inside your data range (A1:B500).
2. Go to **Insert > PivotTable**.
3. In the dialog, confirm the range and choose **New Worksheet**, then click **OK**.
4. In the PivotTable Fields pane:
   - Drag **Product** (Column A) into the **Rows** area.
   - Drag **Sales** (Column B) into the **Values** area (ensure it reads "Sum of Sales"; if not, click the dropdown > Value Field Settings > Sum).
5. You now have a unique list of products with summed totals. Copy and paste as values to a new sheet if you need a static list.

**Use when:** You want a quick, dynamic summary you can refresh.

## Method 2: Consolidate Tool (Great for Static One-Time Merge)

1. Select an empty cell on a new sheet (e.g., D1).
2. Go to **Data > Consolidate**.
3. Set **Function** to **Sum**.
4. In **Reference**, select your range `Sheet1!$A$1:$B$500` and click **Add**.
5. Check **Left column** (and **Top row** if you have headers).
6. Click **OK**. Excel outputs unique products with summed sales.

**Use when:** You want a one-click static result without a pivot table.

## Method 3: SUMIF Formula (Best If You Need Formulas)

1. In Column D, create a unique product list:
   - Use **Data > Remove Duplicates** on a copy of Column A, OR
   - Use `=UNIQUE(A1:A500)` in D1 (Excel 365/2021).
2. In E1, enter:
   ```
   =SUMIF($A$1:$A$500, D1, $B$1:$B$500)
   ```
3. Drag the formula down alongside your unique list.

**Use when:** You want live-updating totals as the source data changes.

## Method 4: Power Query (Best for Recurring Reports)

1. Select your data, then **Data > From Table/Range**.
2. In Power Query Editor, select the **Product** column.
3. Click **Home > Group By**.
4. Set: Group by **Product**, New column name **Total Sales**, Operation **Sum**, Column **Sales**.
5. Click **OK**, then **Home > Close & Load**.

**Use when:** You'll repeat this task regularly — just refresh when data updates.

**My pick for your case:** Start with the **Pivot Table** — it handles 500 rows instantly and requires no formulas.
Judge notes: Excellently satisfies the query with four well-explained methods, exact menu paths, practical examples, and clear guidance on when to use each approach for the user's 500-row scenario.
Claude Haiku 4.5 9/10
# Merging Duplicates & Summing Sales Data

For your 500-row dataset, here are the best methods, ranked by practicality:

## **Method 1: Pivot Table (Recommended for Speed)**
**Best for:** Quick summarization without modifying original data.

1. Select all data (A1:B500, including headers)
2. Go to **Insert > Pivot Table**
3. Choose "New Worksheet"
4. Drag "Product Name" to **Rows**
5. Drag "Sales Amount" to **Values** (auto-sums)
6. Click **OK**

**Result:** Instant summary with totals per product. Copy results to a new sheet if needed.

---

## **Method 2: SUMIF Formula (Best for Keeping Original Sheet)**
**Best for:** Creating a clean summary without altering source data.

1. Create a new area (columns D–E) or separate sheet
2. In column D, list unique product names (manually or use **Data > Remove Duplicates** on a copy)
3. In cell E2, enter:
   ```
   =SUMIF($A$2:$A$500,D2,$B$2:$B$500)
   ```
4. Copy the formula down for all unique products

**Example:** If "Apple" appears in rows 5, 12, and 45 with values 100, 150, 200, the formula returns 450.

---

## **Method 3: Consolidate Tool (Traditional Approach)**
**Best for:** Multi-sheet data or structured ranges.

1. Sort data by Product Name (A–Z)
2. Select **Data > Consolidate**
3. Set **Function** to "Sum"
4. **Reference:** Select your data range ($A$2:$B$500)
5. Check **"Labels in first row"** and **"Left column"**
6. Click **OK**

**Note:** Works best if data is already sorted.

---

## **Method 4: Power Query (Most Robust)**
**Best for:** Recurring data cleaning tasks.

1. Select data (A1:B500)
2. Go to **Data > From Table/Range** (or **Get & Transform Data**)
3. Click **Group By** in the ribbon
4. Group by "Product Name," Sum "Sales Amount"
5. Click **Close & Load**

---

## **Quick Recommendation:**
- **Fastest:** Pivot Table (1–2 minutes)
- **Simplest formula:** SUMIF method
- **Most flexible:** Power Query
- **Cleanest result:** Any of the above; copy/paste as values if needed

**Pro Tip:** After merging, verify totals match your original data sum to ensure accuracy.
Judge notes: Comprehensive, well-structured response with four practical methods ranked by use case, exact menu paths, sample formulas, and clear guidance on when to use each approach—directly and thoroughly addresses the user's specific 500-row sales data scenario with only minor room for improvement (e.g., could include a before/after example screenshot reference).
GPT-5.4 9/10
1) Pivot Table (fastest, no formulas)
- Use when you want a quick summary you can refresh.
- Steps:
  • Click any cell in A:B (assume headers in A1:B1 like Product, Sales).
  • Insert > PivotTable > From Table/Range. Confirm range (e.g., $A$1:$B$501) and choose New Worksheet > OK.
  • In PivotTable Fields: drag Product to Rows; drag Sales to Values.
  • If it shows Count, click Sum of Sales > Value Field Settings > Sum > OK.
  • Optional: To get a flat table, copy the PivotTable results and Paste Special > Values.

2) SUMIF with a unique product list (formula-based)
- Use when you want a normal range that updates with data edits.
- Excel 365 (dynamic arrays):
  • In D2: =UNIQUE(A2:A501)
  • In E2: =SUMIF($A$2:$A$501, D2#, $B$2:$B$501)
  • Format E:E as currency. D2# spills the unique list; E2 returns matching totals.
- Older Excel:
  • Copy A1:A501 to D1:D501.
  • Data > Remove Duplicates (check Product column) > OK.
  • In E2: =SUMIF($A$2:$A$501, D2, $B$2:$B$501)
  • Fill E2 down next to the unique list.

3) Data > Consolidate (one-off merge without formulas)
- Use for a quick static summary on a new sheet.
- Steps:
  • Insert a new sheet.
  • Data > Consolidate.
  • Function: Sum.
  • Reference: select $A$1:$B$501 > Add.
  • Check “Top row” and “Left column” (to use headers and product names as labels).
  • OK. This creates a new list of unique products with summed sales.

4) Power Query (repeatable, best for ongoing updates)
- Use when you’ll append/refresh data regularly.
- Steps:
  • Ensure headers in row 1. Select A1:B501.
  • Data > From Table/Range (check “My table has headers”) > OK.
  • In Power Query: Home > Group By.
    - Group by: Product
    - New column name: Total Sales
    - Operation: Sum
    - Column: Sales
  • Home > Close & Load > Close & Load To… > Table (new worksheet).
  • Next time data changes, Data > Refresh All.

Notes
- Ensure column B is numeric (no text). If needed: select B, Data > Text to Columns > Finish, or use VALUE().
- Choose: Pivot (quick), SUMIF (flexible formulas), Consolidate (one-off static), Power Query (robust refreshable).
Judge notes: Excellently comprehensive response with four practical methods, exact menu paths, relevant formulas, clear use-case guidance, and proper handling of the user's specific 500-row scenario with helpful notes on data validation.
Gemini 2.5 Pro 9/10
Of course. Here are the best methods to merge your duplicate product rows and sum their sales values. For your situation, the PivotTable is the fastest and most flexible option.

### **Method 1: PivotTable (Recommended)**
This is the best method for quick, interactive summaries. It's dynamic, meaning you can easily refresh it if your source data changes.

1.  **Select your data:** Click any cell within your data range (e.g., A1).
2.  **Insert PivotTable:** Go to the **Insert** tab and click **PivotTable**. Excel will automatically select your data range. Click **OK**.
3.  **Arrange Fields:** A new sheet will open with a "PivotTable Fields" pane on the right.
    *   Drag **"Product Name"** from the field list into the **Rows** area.
    *   Drag **"Sales"** into the **Values** area.

Excel will instantly create a summary table with a unique list of products and their corresponding total sales.

### **Method 2: Consolidate Tool**
This is a great tool for creating a simple, static summary without the formatting of a PivotTable.

1.  **Select a starting cell:** Click an empty cell where you want the summary table to appear.
2.  **Open Consolidate:** Go to the **Data** tab > **Data Tools** group > click **Consolidate**.
3.  **Set it up:**
    *   Ensure **Function** is set to **Sum**.
    *   In the **Reference** box, select your data range, including headers (e.g., `A1:B501`). Click **Add**.
    *   Under "Use labels in," check both **Top row** and **Left column**.
4.  Click **OK**. A static summary
Judge notes: Excellent response that directly addresses the user's query with multiple well-explained methods (PivotTable, Consolidate), exact menu paths, step-by-step instructions, and appropriate method selection for the 500-row dataset; only minor issue is the output appears cut off mid-sentence.
Grok 4.1 Fast Reasoning 9/10
### 1. **Pivot Table (Recommended: Fastest for summaries, dynamic updates)**
   - Select your data (A1:B501, including headers).
   - Go to **Insert > PivotTable > OK** (new sheet).
   - Drag "Product names" (Col A) to **Rows**.
   - Drag "Sales amounts" (Col B) to **Values** (auto-sums; right-click > Summarize by > Sum if needed).
   - Result: Unique products in Col A, summed sales in Col B. Refresh via right-click > Refresh for updates.
   - *Use when*: Quick analysis, no data alteration.

### 2. **Power Query (Best for repeatable/clean data transform)**
   - Select data > **Data > From Table/Range** (creates query).
   - In Power Query Editor: **Home > Group By**.
   - Group by "Product names"; add aggregation: New column "Total Sales" > Sum > "Sales amounts".
   - **Home > Close & Load** to new sheet.
   - *Use when*: Large datasets (500+ rows), refreshable, or ETL needed. Edit query for changes.

### 3. **SUMIF Formula (Simple, formula-based; Excel 365 ideal)**
   - In new sheet Col A: List unique products (Data > Sort A-Z on original, copy uniques; or **=UNIQUE(A:A)** if 365).
   - Col B: `=SUMIF($A$2:$A$501, A2, $B$2:$B$501)` (drag down).
   - *Use when*: Small lists, want formulas over tools.

### 4. **Consolidate (Basic, less flexible)**
   - Copy data to new sheet.
   - **Data > Consolidate > Sum > Add ranges** (select each unique product range manually—tedious for 500 rows).
   - *Use when*: Few categories; avoid for duplicates.

Pivot/Power Query handle 500 rows effortlessly without destroying originals. Copy results if needed. (187 words)
Judge notes: Excellent response that directly addresses the query with multiple methods ranked by practicality, includes exact menu paths and formulas, provides appropriate use-case guidance, and is well-structured and actionable for the user's specific 500-row scenario.

What makes these work

  1. 01
    Clean keys before you aggregate

    Trailing spaces, mixed case, and invisible characters will split what should be one group into several. Run TRIM and either UPPER or PROPER on your key column first, or use Power Query's Clean and Trim transforms. Fix the keys once and every method downstream works correctly.

  2. 02
    PivotTable for one-off, Power Query for repeat

    If you're cleaning this file once and never again, a PivotTable takes 30 seconds. If the source file gets updated weekly and you want to click Refresh, invest five minutes in Power Query Group By. The reusability difference is massive.

  3. 03
    Use SUMIFS when you need multiple key columns

    SUMIF handles one criterion. SUMIFS handles several, which matters when your 'duplicate' is really a combination like Customer plus Region plus Month. Syntax: =SUMIFS(sum_range, criteria_range1, criteria1, criteria_range2, criteria2).

  4. 04
    Copy to a new sheet before destructive edits

    Remove Duplicates and Consolidate modify data in place. Always work on a copy so you can compare totals against the original as a sanity check. If your new sum doesn't match the grand total of the source, something went wrong.

More example scenarios

#01 · Merging repeated customer orders into totals
Input
Column A lists customer names (many duplicates like 'Acme Corp' appearing 12 times), Column B has order amounts in USD. There are 3,400 rows. I need one row per customer with their total spend, sorted by total descending.
Expected output
Recommends a PivotTable: select A1:B3400, Insert > PivotTable, drag Customer to Rows and Amount to Values (set to Sum), then right-click a total and Sort > Largest to Smallest. Also provides a SUMIF alternative: =SUMIF(A:A, D2, B:B) where D2 holds a unique customer from Remove Duplicates.
#02 · Consolidating multi-warehouse SKU inventory
Input
Sheet has SKU in column A, Warehouse in column B, Quantity in column C. Same SKU appears once per warehouse. 8,000 rows across 40 warehouses. I want total quantity per SKU, ignoring warehouse.
Expected output
Recommends Power Query: Data > From Table/Range, then Group By on SKU with aggregation Sum of Quantity. Returns clean two-column output (SKU, TotalQty) that refreshes when source changes. Provides the M code: = Table.Group(Source, {"SKU"}, {{"TotalQty", each List.Sum([Quantity]), type number}}).
#03 · Combining vendor expenses with multiple numeric columns
Input
Expense log with Vendor (col A), Subtotal (B), Tax (C), Total (D). 'Staples' appears 47 times, 'AWS' appears 112 times, plus 200 other vendors. I need one row per vendor summing all three numeric columns.
Expected output
Recommends PivotTable with Vendor in Rows, and Subtotal, Tax, Total each dragged to Values as Sum. Alternatively, use Remove Duplicates on a copy of column A, then =SUMIF($A:$A, $F2, B:B) and drag right across columns and down for all unique vendors.
#04 · Rolling up weekly timesheet entries per project
Input
Timesheet export: Employee (A), Project (B), Hours (C), Date (D). Same employee-project combo appears multiple times across weeks. I want total hours per unique Employee+Project pair, ignoring date.
Expected output
Recommends creating a helper column E with =A2&"|"&B2, then PivotTable using the combo as Rows and Sum of Hours as Values. Or in Power Query: Group By with two key columns (Employee, Project) and Sum aggregation on Hours. Shows both paths with screenshots described step by step.
#05 · Cleaning messy duplicates before summing
Input
Column A has company names but with inconsistent casing and trailing spaces: 'Acme corp', 'ACME Corp ', 'acme corp'. Column B has revenue. About 1,200 rows. Straight SUMIF treats them as different.
Expected output
Two-step fix: add helper column C with =TRIM(PROPER(A2)) to normalize, then PivotTable on column C summing column B. For a formula-only route: =SUMPRODUCT((TRIM(LOWER($A$2:$A$1201))=TRIM(LOWER(D2)))*$B$2:$B$1201).

Common mistakes to avoid

  • Forgetting to set Values to Sum

    PivotTables default to Count for text-heavy data and sometimes for mixed columns. If your totals look like row counts instead of dollar amounts, right-click the value field and change Summarize Values By to Sum.

  • Leaving trailing spaces in keys

    'Acme Corp' and 'Acme Corp ' look identical but Excel treats them as different values, so you get two rows in your output instead of one. Always TRIM the key column before aggregating or the totals will be silently wrong.

  • Using Remove Duplicates on the whole row

    Remove Duplicates only removes rows that match across every selected column, so if any numeric value differs it keeps both. This doesn't sum anything, it just deletes exact duplicates. Use it for cleanup, not for aggregation.

  • Summing across merged cells

    Merged cells break SUMIF, PivotTables, and Power Query in different ways. Unmerge everything in your data range before aggregating and use center-across-selection formatting if you need the visual effect.

  • Not refreshing the PivotTable after edits

    If you change source data, the PivotTable keeps showing old totals until you right-click and choose Refresh. People often email screenshots of stale numbers without realizing. Set the PivotTable to refresh on file open under PivotTable Options.

Related queries

Frequently asked questions

What's the fastest way to merge duplicate rows and sum values in Excel?

A PivotTable. Select your data, press Alt+N+V, drag the key column to Rows and the numeric column to Values. You get one row per unique key with sums in under a minute. No formulas needed.

How do I combine duplicate rows and sum values without a PivotTable?

Copy the key column to a new location, use Data > Remove Duplicates to get a unique list, then write =SUMIF(original_key_range, unique_key_cell, value_range) next to each unique key. Drag down. You now have a flat table of unique keys and their summed values.

Can Power Query merge duplicates and sum values automatically?

Yes, and it's the best option if your data updates regularly. Load the table into Power Query, choose Group By, pick your key column, and set the aggregation to Sum on your numeric column. Load it back to Excel and hit Refresh whenever the source changes.

How do I sum values with multiple duplicate criteria, like customer and month?

Use SUMIFS or a PivotTable with two fields in Rows. SUMIFS syntax is =SUMIFS(amount_col, customer_col, "Acme", month_col, "2024-01"). In a PivotTable, drag both Customer and Month to the Rows area and the amount to Values as Sum.

Why does SUMIF return zero for rows that clearly have values?

Usually because your numeric column is stored as text. Select the column, click the yellow warning triangle, and choose Convert to Number. Also check for trailing spaces in the criteria column using TRIM, since 'Acme' and 'Acme ' won't match.

How do I merge duplicate rows and keep other text columns too?

Aggregation forces a choice for non-numeric columns. In a PivotTable you can add text fields to Rows to group by them. In Power Query's Group By, use aggregations like First, Max, or a comma-separated concatenation via Text.Combine to preserve text values across the merged rows.