Search code examples
excelexcel-formulaexcel-365

How to sum multiple columns using GROUPBY() function?


I have the following sample dataset.

Item Value1 Value2
a 5 15
b 10 20
c 5 15
d 10 20
a 5 15
b 10 20
c 5 15
d 10 20
a 5 15
b 10 20
c 5 15
d 10 20

I want to sum column wise values based on unique items. So, my output will look like-

a 15 45
b 30 60
c 15 45
d 30 60

Currently I can achieve desired result by the following formula-

=LET(x,UNIQUE(B4:B15),HSTACK(x,SUMIFS(C4:C15,B4:B15,x),SUMIFS(D4:D15,B4:B15,x)))

Can I get same result by GROUPBY() function? =GROUPBY(B4:B15,C4:C15,SUM) this formula sum a single column.

Screenshot for better understanding. enter image description here


Solution

  • I got the trick of GROUPBY() function. It supports to input multiple column range and SUM values for individuals columns by grouping items. The following formula solved my issue.

    =GROUPBY(B3:B15,C3:D15,SUM,3)
    

    enter image description here