4
votes

I'm running a QUERY with a SUM and GROUP BY, but I'd like to aggregate multiple distinct values from the rows into a single row and column. I'm looking to concatenate all those values together.

Current Table:

Person Widget Count
Bill Red 12
Bill Blue 9
Sarah Yellow 4
Bill Yellow 1
Sarah Orange 10

Expected Table:

Person Widget Count
Bill Red, Blue, Yellow 22
Sarah Yellow, Orange 14
1
Using a script would be easier, sql doesn't have a method for returning multiple records as one...WhiteHat

1 Answers

13
votes

You can use the filter and join functions to help:

To get a unique list of names:

=UNIQUE(A3:A)

To join the widgets:

=join(",",filter(B:B,A:A=E3))

To sum the values:

=sum(filter(C:C,A:A=E3))

enter image description here