HomeGoogle DocsSpreadsheetCombine Similar Rows and Sum Values in Google Sheets

Combine Similar Rows and Sum Values in Google Sheets

Published on

Query and Pivot Table are the two options in Google Sheets to combine and total duplicate/similar rows.

But you can also use a tricky Unique+Sumif combination formula.

In this Google Sheets tutorial, I am detailing how to combine similar rows and sum values in Google Sheets using both the Query and Unique+Sumif combo.

For the example purpose, I am using a basic set of data.

It’s not realistic-looking data. But with this, I hope I can well explain the formulas.

Sample Data:

Formula to Combine Similar Rows and Sum Values

I am only using two-column data in the first example.

In the last part of this tutorial, you can learn how to use multiple columns in similar calculations.

Combining duplicate rows and sum values in Google Sheets is not a difficult task.

Basic Query or Sumif knowledge is required for this.

Even if you don’t know how to use Query, you may go through my formula to gain the basic skill to combine similar rows and sum values in Google Sheets.

Query Formula to Combine Similar Rows and Sum Values in Google Sheets

Formula:

=query(B3:C11,"Select B, Sum(C) group by B")

Suppose you may want to include an unlimited number of rows in the Query to cover future values.

In that case, modify the above Query as below.

=query(B3:C,"Select B, Sum(C) where B is not null group by B")

Note:- The above two Query formulas that combine duplicate rows are based on the sample data above (screenshot).

Now see how to combine duplicate rows in Google Sheets and sum the value column using another formula. I am using Unique and Sumif this time.

Formula:

=index(sumif(B3:B11,unique(B3:B11),C3:C11))

OR use;

=ArrayFormula(sumif(B3:B11,unique(B3:B11),C3:C11))

The above two formulas would only return the sum of duplicates.

So first, use the below Unique formula in one cell and either of the above two formulas in another cell.

Use the above formula in cell G4 and the following formula in cell F4.

=unique(B3:B11)

The role of the Index in the first formula and the ArrayFormula in the second formula is the same.

What’s that?

Since the Sumif can’t return an array result, I mean multiple values, we must use an Array Formula with it.

Note:- Don’t forget to use the keyword “Duplicates” to find several duplicate removal tips on this site.

Combines Duplicates in Rows and Sum the Values (Multiple Column Duplicates)

First, see my sample Google Sheets data and the formula output.

sum duplicate rows in Google Sheets

First, see my sample Google Sheets data and the formula output.

Here Query is the proper solution.

=query(B3:D,"Select B,C, sum(D) where B is not null group by B,C")

This time, if you want, you can use Sumif as below.

The Unique Formula in cell G4:

=UNIQUE(B3:C8)

The Sumif Formula in cell I4:

=ArrayFormula(sumif(B3:B8&C3:C8,G4:G7&H4:H7,D3:D8))
sum two column duplicates in Sheets

Conclusion

In my examples, I recommend the formulas based on Query to my readers.

I have just included the Sumif to make you understand the flexibility of the functions available in Google Sheets.

I hope you have enjoyed your stay.

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Counting XLOOKUP Results with COUNTIFS in Excel and Google Sheets

We can use COUNTIF or COUNTIFS alongside an XLOOKUP formula to conditionally count the...

Appointment Schedule Template in Google Sheets

An appointment schedule template in Google Sheets can assist you in efficiently managing your...

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Running Total By Month in Excel

This tutorial demonstrates how to calculate the running total by month in a range...

More like this

Appointment Schedule Template in Google Sheets

An appointment schedule template in Google Sheets can assist you in efficiently managing your...

Creating Sequential Dates in Equally Merged Cells in Google Sheets

Do you know how to create sequential dates in equally merged cells across a...

Interactive Random Task Assigner in Google Sheets

You have multiple tasks and multiple people. Here's a fun way to randomly assign...

15 COMMENTS

  1. Hi, I’m working on similar to it.

    I need to combine a duplicate row and sum the values of 2 columns differently.

    After getting that, I need to combine my filter function with the query function.

    Filter Function:

    =filter(C5:E,A5:A=B1) [this is for the dropdown category]

  2. Hello,

    I am doing something similar, but I need to separate the data by date. I cannot seem to get the formula right. Can you assist?

    • Hi, Janira Iglesias,

      Here is an example.

      Data in Columns:

      A – Dates
      B – Item Description
      C – Quantity.

      The formula in D1:

      =query(A1:C,"Select A,B,sum(C) where A is not null group by A,B")

      Please try it first. If that doesn’t help, make a sample and share that Sheet’s address/URL via the comment below.

  3. Hi Prashanth,

    hope you are well. First of all thanks so much for sharing your knowledge with the world. Very highly appreciated.

    I would have one question sum values part. I used your Merge/Combine rows solutions and it’s working fine for my use case. Except for one part.

    I’m using it for consolidation Orders from an e-commerce shop so I get one row per Order showing all different order positions and items that are in one basket/order.

    So origin Data shows two rows when two items are ordered. In one column it says “order position number” ..and because it’s two items its two rows with “order position number” #1 and the next row #2.

    I would like to not sum up but only show in the final table “order positions: #2” (as there are two items). Summing up would show #3.

    So is there a way to either only take the second value = #2 or identify the highest value? (it could also be somebody orders 5 times the same item, then I would have 1 row for the order showing order positions =5)

  4. Hello, are you still taking inquiries? I am trying to consolidate two sets of information that have repeating values (as shown in your video) but I would like a different result. Are you still monitoring this?

    Thanks!

    • Hi, Louie N,

      Nope! But I’ll try to help you in my leisure if you can share with me a sample of what you are working on. Use the ‘Reply’ below to share yours sheet. The link won’t be published here to protect your privacy.

      NB: Just a sample in 5-10 rows and a few columns.

    • The below formula is as per the sample data and the formula used in the example in my tutorial.

      =ArrayFormula(if(len(G4:G),sumif(B3:B&C3:C,G4:G&H4:H,D3:D),))

      In your case, it might be len(K2:K)

      Best,

  5. Hey Prashanth,

    I’m still having issues doing this. Since I can’t post a screenshot, I will try to explain it here.

    Column C has Multiple Values (Will Continue to grow with different Values)
    Column D has Multiple Values (Will Continue to grow with different Values)
    Column E is what I need the SUM for and is numeric

    Thank you in advance,

    Adam B. Yuro

    • Hi, Adam,

      You can try this Query. In this row#1 is considered as the header row.

      =query(C1:E,"Select C,D, sum(E) where C is not null group by C,D",1)

      If there is no header, then the Query formula would be like this.

      =query(C1:E,"Select C,D, sum(E) where C is not null group by C,D",0)

      Both of these formulas won’t work if you are from EU countries. Then use the Query as below.

      =query(C1:E;"Select C,D, sum(E) where C is not null group by C,D";1)

      If not helpful? Then try to share your Sheets’ link (no personal/confidential data)

      Best,

  6. This is great and thank you! Is there a way to not make the resulting data a new set of columns, but rather rearrange and modify the original data to show the sums?

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.