Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheet Query - Group / concatenate multiple rows

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
like image 441
Tom Avatar asked Dec 10 '22 17:12

Tom


1 Answers

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

like image 101
Aurielle Perlmann Avatar answered Mar 11 '23 21:03

Aurielle Perlmann