Excel Formulas to Sum Duplicate Rows with Unique Keys

📅 May 15, 2026 📝 Sarah Miller

Consolidating duplicate row data while maintaining unique keys is a recurring headache for data analysts striving for report accuracy. While native Pivot Tables offer a standard approach to aggregation, they often lack the real-time flexibility required for dynamic dashboard reporting. Utilizing a robust formulaic solution ensures your summaries update instantly, eliminating manual recalculation errors. Stipulation: This streamlined method requires Excel 365 or 2021 to leverage dynamic array functionality. For example, combining =UNIQUE(A2:A100) with =SUMIF(A2:A100, D2#, B2:B100) seamlessly condenses duplicate keys. Below, we outline the exact step-by-step formula implementation to clean and streamline your operational datasets.

Excel Formulas to Sum Duplicate Rows with Unique Keys

Whether you are managing sales records, analyzing warehouse inventory, or tracking monthly business expenses, you will frequently encounter datasets with duplicate keys. For instance, a product ID, customer name, or transaction date might appear multiple times across hundreds of rows, with different numeric values associated with each occurrence.

Consolidating these duplicates into a clean, summarized list of unique keys alongside their total summed values is a core data-cleaning skill. Excel offers several robust ways to achieve this, ranging from dynamic array formulas to database-style tools like Power Query and Pivot Tables. This guide explores the best techniques to sum duplicated rows with unique keys, tailored to your version of Excel and your workflow requirements.

The Sample Dataset

To demonstrate these solutions, let's assume we have the following raw transactional dataset in columns A and B:

Column A (Product Key) Column B (Sales Value)
Prod-A120
Prod-B250
Prod-A80
Prod-C310
Prod-B150
Prod-A110

Our objective is to generate a consolidated summary list showing each unique product key once, with the sum of its corresponding sales values:

  • Prod-A: 310 (120 + 80 + 110)
  • Prod-B: 400 (250 + 150)
  • Prod-C: 310

Method 1: The Modern Dynamic Formula Approach (Excel 365 & 2021)

If you are using Microsoft 365 or Excel 2021, the easiest and most powerful method is to combine the dynamic array function UNIQUE with the classic SUMIF or SUMIFS function. This creates an automated dashboard that dynamically updates as your source data changes.

Step 1: Extract the Unique Keys

Select an empty cell where you want your summary to begin (e.g., cell D2) and enter the following formula:

=UNIQUE(A2:A7)

Press Enter. Excel will automatically "spill" the unique list of product keys downward into cells D2, D3, and D4.

Step 2: Sum the Values for Each Unique Key

In the adjacent cell (E2), enter the SUMIF formula. Since we want our sum range to dynamically adjust to the size of our spilled unique list, we can use the spill operator (#):

=SUMIF(A2:A7, D2#, B2:B7)

How this works:

  • A2:A7 is the criteria range containing the original duplicated keys.
  • D2# references the entire spilled range starting at D2. This tells Excel to run the calculation for every unique item generated by the UNIQUE formula.
  • B2:B7 is the actual range of values we want to sum.

The beauty of this method is that if you add new products or rows to your dataset (provided you use Excel Tables or expand your range references), the summary list and totals will expand or contract automatically.


Method 2: The Single-Formula Solution using GROUPBY (Excel 365 Beta/Current Channel)

For users on the cutting edge of Microsoft 365, Excel has introduced a revolutionary function designed specifically for this purpose: GROUPBY. This function allows you to perform the entire operation-extracting keys and summing values-in a single cell formula.

In your destination cell, enter the following formula:

=GROUPBY(A2:A7, B2:B7, SUM, 3, 0)

Syntax Breakdown:

  • row_fields (A2:A7): The column containing the keys you want to group and unique-ify.
  • values (B2:B7): The column containing the numeric values you want to aggregate.
  • function (SUM): The math operation you wish to perform (you can also use AVERAGE, COUNT, MAX, etc.).
  • headers (3): An optional parameter indicating whether your selected range has headers and if they should be shown in the output.
  • sort_order (0): An optional parameter to control sorting.

This single formula generates both the unique row headers and the summed results instantly, complete with a total row at the bottom if desired.


Method 3: The Traditional Method (Excel 2019 and Older)

If you are working on an older version of Excel that does not support dynamic array functions like UNIQUE, you can still achieve this with a quick two-step manual process.

Step 1: Extract Unique Keys Manually

  1. Copy your column of duplicated keys (A2:A7).
  2. Paste it into a new column (e.g., column D).
  3. Select the pasted column.
  4. Go to the Data tab on the Ribbon.
  5. Click Remove Duplicates in the Data Tools group.
  6. Ensure your settings are correct and click OK. You are now left with a static list of unique keys.

Step 2: Write a Standard SUMIF Formula

In cell E2, enter the classic SUMIF formula:

=SUMIF($A$2:$A$7, D2, $B$2:$B$7)

Note the use of absolute references ($) for the ranges. This ensures that as you drag the formula down to match your unique list, the lookup ranges remain locked.

Drag the fill handle down from E2 to the bottom of your unique list to calculate the sums for all keys.


Method 4: Pivot Tables (The No-Formula, Interactive Way)

If you prefer to avoid formulas altogether, Pivot Tables are the fastest and most scalable solution. They work on all versions of Excel and are highly optimized for large datasets.

  1. Select your source dataset (including the column headers in row 1).
  2. Go to the Insert tab on the Ribbon and click PivotTable.
  3. Choose where you want to place the Pivot Table (New Worksheet or Existing Worksheet) and click OK.
  4. In the PivotTable Fields pane on the right:
    • Drag the Product Key field into the Rows area.
    • Drag the Sales Value field into the Values area.

Excel will instantly output a unique list of products alongside their consolidated sum. If you add new data to your source table, simply right-click anywhere inside your Pivot Table and select Refresh to update the figures.


Method 5: Power Query (Best for Automated Workflows)

For users dealing with millions of rows, external databases, or files that need to be updated daily, Power Query is the ultimate tool. It allows you to build a reproducible data-cleaning pipeline.

  1. Select your dataset, go to the Data tab, and click From Table/Range (this will convert your data into an official Excel Table if it isn't one already).
  2. In the Power Query Editor window, click on your Key column header to select it.
  3. Go to the Home or Transform tab and click on Group By.
  4. In the dialog box that appears:
    • Ensure the "Group by" column is set to your key column (e.g., Product Key).
    • Set the New column name to something like Total Sales.
    • Set the Operation to Sum.
    • Set the Column to aggregate to your values column (e.g., Sales Value).
  5. Click OK.
  6. Go to the Home tab and click Close & Load to output the consolidated list back into your Excel workbook as a clean table.

Summary: Which Method Should You Use?

Choosing the right method depends largely on your version of Excel and how often your source data updates:

  • Use Method 1 (UNIQUE + SUMIF) if you use Microsoft 365 and want an automated, formula-driven dashboard that recalculates instantly on data entry.
  • Use Method 2 (GROUPBY) if you are on the newest Office Insider/Beta builds and want the cleanest, single-cell setup possible.
  • Use Method 3 (Remove Duplicates + SUMIF) if you are sharing your spreadsheet with users on older Excel versions (Excel 2016/2013).
  • Use Method 4 (Pivot Tables) if you have a massive dataset and want to analyze or filter your data interactively without typing complex formulas.
  • Use Method 5 (Power Query) if your data is imported from external sources and requires automated, repeatable transformations before summing.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.