代码之家  ›  专栏  ›  技术社区  ›  Code Guy

使用查询公式连接具有分隔符的列数据和具有其他分隔符的行数据

  •  0
  • Code Guy  · 技术社区  · 3 年前

    Here is the sheet

    我有一个数据

    enter image description here

    我有一个查询公式

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

    查询的输出为

    enter image description here

    我需要将输出结果重新定义为

    (true=true OR true=true OR true=true)AND

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

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

    0 回复  |  直到 3 年前
        1
  •  1
  •   Aresvik    3 年前

    尝试

    =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 照着

    enter image description here

    这在以下范围内效果更好:

    =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)&"\)$","\)"))
    

    enter image description here

        2
  •  1
  •   Dang D. Khanh    3 年前

    现在可能是 IF 工作。
    试试这个:

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

    enter image description here