简体   繁体   中英

Is there a way to use arrayformula in google sheet to join text with conditions?

Is there a way to get the result column in the picture below? All i want to do is text join the Col1 if the corresponding Col2 belongs to the same groups (EG 1,2,3....). Reminded that I want to use arrayformula instead of dragging down the "normal" formula myself everytime.

在此处输入图像描述

Use this formula
Or Make a copy of this example sheet.

=ArrayFormula({"Result";
                IF(A2:A="",,
                BYROW(B2:B,
                LAMBDA(v,JOIN(", ",FILTER(A2:A,B2:B=v)))))})

在此处输入图像描述

Great news for google-sheet lovers that google releases new lambda formulas. You can use BYROW() function to make it spill array. Try below formula.

=BYROW(C3:C9,LAMBDA(x,JOIN(",",FILTER(B3:B9,C3:C9=x))))

To refer entire column use FILTER() function for BYROW() .

=BYROW(FILTER(C3:C,C3:C<>""),LAMBDA(x,JOIN(",",FILTER(B3:B,C3:C=x))))

在此处输入图像描述

Suppose my range of data from B3:C9, want to group the result according the the Column C (or Col2) Here is the formula i googled without using the Lambda function

=ARRAYFORMULA(REGEXREPLACE(TRIM(SPLIT(FLATTEN(  QUERY(QUERY({ROW(C3:C9), C3:C9&"×", B3:B9&","},   "select max(Col3) where not Col2 starts with '×'    group by Col1 pivot Col2"),,7^7)), "×")), ",$", ))

Notice the 7^7 is the (length of the data)^(length of the data). ie from 3 to 9, there are 7 data.

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