Search code examples
google-sheetsgoogle-sheets-query

Group data by distinct names with their values sum


I have data in google-sheets in the next format (multiple paired columns):

Source: | Value: | Source: | Value: | ...
Name1     100    |  Name1     20
Name2     50     |  Name2     60
Name1    -10     |  Name3     600
Name3    -150    |  Name2     -700
Name1     500    |  Name2     50
...

How can I group it by name and sum values? I need to achieve this:

uniq(Source): | sum(Value):
Name1           1000
Name2           1400
Name3           -100
...

Solution

  • =QUERY({A2:B; C2:D}, 
     "select Col1,sum(Col2) 
      where Col1 is not null 
      group by Col1 
      label sum(Col2)''")
    

    0