Merge multiple rows based on column and sum values (Excel, Google Refine, Google spreadsheet)

calendar_today Asked Feb 17, 2013
thumb_up 15 upvotes
history Updated April 16, 2026

Question posted 2013 · +6 upvotes

I have large amount of rows, which look like:

| Name   | Value |
|--------|-------|
| name 1 | 12    |
| name 1 | 10    |
| name 1 | 1     |
| name 2 | 55    |
| name 3 | 1     |
| name 3 | 8     |

I need to merge all rows into one row based on column “Name” and sum “Value” in relevant rows. Result should be:

| Name   | Value |
|--------|-------|
| name 1 | 23    |
| name 2 | 55    |
| name 3 | 9     |

Rows with the same “Name” could be 0-n.

How can I do it in Google Refine or in Excel/Google Spreadsheet?

I am thinking of it, but with no solution.

Thank you a lot!

Accepted answer +15 upvotes

In OpenRefine or Google Refine:

  • Sort by Name column (if not already sorted) and make sort permanent
  • Blank Down on name column to remove duplicate values
  • On Value column, do Edit Cells -> Merge multi-valued cells
  • On same column, do Edit Cells -> Transform with a GREL expression of forEach(value.split(','),v,v.toNumber()).sum()
  • Facet by Blank on Name column, and select True (ie blank rows)
  • Use All -> Edit Rows -> Remove all matching rows to delete the redundant rows

Top excel Q&A (6)

+15 upvotes ranks this answer #42 out of 167 excel solutions on this site — top 25%.