【问题标题】:joining column data with a delimiter and row data with other delimiter using a query formula使用查询公式将带有分隔符的列数据和带有其他分隔符的行数据连接起来
【发布时间】:2021-06-25 06:37:19
【问题描述】:

Here is the sheet

我有一个数据

我有一个查询公式

=query(ARRAYFORMULA(IF(H1:H5<>"","Col" & MATCH(G1:G5,'VIEW_WhatsppFormat Sheet'!1:1,0) & " = '" & split(H1:H5, ",",false,true) & "'","true = true")))

查询的输出是

我需要将输出结果重构为

(true = true OR true = true OR true = true) AND (Col8 = 'Not Reachable' OR Col8 = 'Lost' OR Col8 = 'Call Back Back') AND (Col9 = 'Anelio' OR Col9 = '巴亚交界处' Col9 = '') 等等

这意味着每列都需要用 OR 组合,所有行都需要用 AND 组合。我本可以使用硬编码公式,但列数是动态的

如何以这种方式组合数据?

【问题讨论】:

    标签: excel google-sheets google-sheets-formula


    【解决方案1】:

    试试:

    =arrayformula(regexreplace(substitute("("&textjoin(" OR ",1,{A11:D15,flatten(split(rept(char(9999)&" ",counta(A11:A15))," "))})&")"," OR "&char(9999)&" OR ",") AND ("),"\ OR\ "&char(9999)&"\)$","\)"))
    

    相应地调整A11:D15的范围。

    这对范围更有效:

    =arrayformula(regexreplace(substitute("("&textjoin(" OR ",1,if(A:A<>"",{A:D,flatten(split(rept(char(9999)&" ",max(row(A:A)))," "))},))&")"," OR "&char(9999)&" OR ",") AND ("),"\ OR\ "&char(9999)&"\)$","\)"))
    

    【讨论】:

      【解决方案2】:

      这可能是IF 工作的时候了。
      试试这个:

      =arrayformula(replace(textjoin("",,if(column(A1:C3)=1,") and(" & A1:C3 ," OR " & A1:C3 )) &")",1,len(") AND "),""))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-08
        相关资源
        最近更新 更多