Search code examples
arraysgoogle-sheetssummatchgoogle-query-language

How can I merge duplicate rows in a Spreadsheet while summig the numerical columns?


My Project Reports come from two different sources as we have changed the Project Management tool middle of the year. Therefore, I have prepared two tabs within a Google Spreadsheet with the data from the two systems under same set of headings. Then I combined the two sheets into one using the following query,

=QUERY({'Sheet1'!A1:I1000;'Sheet2'!A2:I1000},"select * where Col1 <>''")

Some of my projects are present within the both the list as they were started early in the year. In order to avoid duplicates I need to merge the two rows representing the same project into one. The project names are identical. However, I need to get the sum of some of the columns such as the 'Time Spent' in order to receive the total value for the whole period. At the same time, columns such as ' Project Owner' are identical among the two rows. How can I combine these duplicate rows into single rows while merging the selcted columns? Thank you in advance for your support!


Solution

  • syntax is:

    =QUERY({Sheet1!A1:B; Sheet2!A2:B}, 
     "select Col1,sum(Col2)
      where Col1 is not null 
      group by Col1 
      label sum(Col2)''")
    

    where A column is text and B column are numeric values