简体   繁体   English

有没有办法在谷歌工作表中使用 arrayformula 来加入有条件的文本?

[英]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....).如果相应的 Col2 属于相同的组(EG 1,2,3 ....),我想要做的就是文本加入 Col1。 Reminded that I want to use arrayformula instead of dragging down the "normal" formula myself everytime.提醒我想使用 arrayformula 而不是每次都自己拖下“正常”公式。

在此处输入图像描述

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.谷歌发布新的 lambda 公式对于 google-sheet 爱好者来说是个好消息。 You can use BYROW() function to make it spill array.您可以使用BYROW() function 使其溢出数组。 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() function 。

=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假设我的数据范围来自 B3:C9,想要根据列 C(或 Col2)对结果进行分组这是我在不使用 Lambda ZC1C425268E68385D1AB5079C17A 的情况下搜索的公式

=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).注意 7^7 是(数据长度)^(数据长度)。 ie from 3 to 9, there are 7 data.即从3到9,有7个数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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