Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List unique values in 1 column and concatenate corresponding values in other column

Example

Column C should contain the unique values from column A, and in column D it should combine the corresponding values in column B as shown in the attached example.

Ideally using a formula with QUERY or ARRAYFORMULA (so not having to drag down the formula), since this list is generated automatically and can be very long (10000+ rows)

I had created a google script to do this, but hope to be able to do this with formula because of performance reasons.

like image 676
dean2020 Avatar asked Oct 15 '25 18:10

dean2020


1 Answers

try like this:

=ARRAYFORMULA({SORT(UNIQUE(FILTER(A:A, A:A<>""))),
 REGEXREPLACE(SUBSTITUTE(TRIM(TRANSPOSE(QUERY(QUERY(QUERY(
 IF(A:A<>"", {A:A, B:B&","}, ), 
 "select max(Col2) where Col1 !='' group by Col2 pivot Col1"), 
 "offset 1", 0),,999^99))), ", ", ","), ",$", )})

enter image description here

like image 165
player0 Avatar answered Oct 18 '25 10:10

player0



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!