简体   繁体   中英

Group everything by Column A and have Column B be a comma-delimited list of values

I've got a Google Sheets worksheet with data like this:

Product Attribute
Product A Cyan
Product B Cyan
Product C Cyan
Product A Magenta
Product C Magenta
Product B Yellow
Product C Yellow
Product A Black
Product B Black

What I'd like to do group everything by Column A and have Column B be a comma-delimited list of values that share Column A in common, like so:

Product Attribute
Product A Cyan,Magenta,Black
Product B Cyan,Yellow,Black
Product C Cyan,Magenta,Yellow,Black

Query? Arrayformula? Both?

use:

=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(FLATTEN(
 QUERY(QUERY({ROW(A1:A), A1:A&"×", B1:B&","}, 
 "select max(Col3) where not Col2 starts with '×' 
  group by Col1 pivot Col2"),,9^9)), "×")), ",$", ))

在此处输入图像描述

try:

={UNIQUE(FILTER(A:A, B:B<>"")), BYROW(UNIQUE(FILTER(A:A, B:B<>"")), 
 LAMBDA(aa, JOIN(", ", FILTER(B:B, A:A=aa))))}

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM