如何在QUERY的第二个参数中使用多个TEXT函数?

时间:2019-06-24 00:07:32

标签: google-sheets google-sheets-formula array-formulas google-sheets-query google-query-language

在第二个参数中将Query函数与text()To_text()函数一起使用对我来说完全正常,如以下示例所示:

=QUERY({June2019!$M$3:$Z;July2019!$M$3:$Z;August2019!$M$3:$Z},"select 
 SUM(Col5) where Col1 > "&text((Column()-2)*5,"#")&" and Col1 <= 
 "&text((Column()-1)*5,"#")&" label SUM(Col5) ''")

但是,一旦我以更复杂的方式使用此查询功能,就会收到以下两个错误之一:

=IF((ISBLANK(B27:27)=False), 
 (QUERY({June2019!$M$3:$Z;July2019!$M$3:$Z;August2019!$M$3:$Z},"select 
 SUM(Col5) where (Col1 > "&text((Column()-2)*5,"#")&") and (Col1 <= 
 "&text((Column()-1)*5,"#")&") label SUM(Col5) 
 ''"))/(QUERY({June2019!$M$3:$Z;July2019!$M$3:$Z;August2019!$M$3:$Z},"select 
 COUNT(Col5) where (Col1 > "&text((Column()-2)*5,"#")&") and (Col1 <= 
 "&text((Column()-1)*5,"#")&") label COUNT(Col5) ''")),)
  

错误:   查询完成,输出为空。


  

错误:   无法解析函数QUERY参数2的查询字符串:PARSE_ERROR:在第1行第24列遇到““ Col1”“。期望其中之一:”(“ ...”(“ ...

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

尝试:

=ARRAYFORMULA(IF(ISBLANK(B27:27)=FALSE, 
 QUERY({June2019!$M$3:$Z; July2019!$M$3:$Z; August2019!$M$3:$Z}, 
 "select SUM(Col5) 
  where Col1 >  "&(COLUMN()-2)*5&" 
    and Col1 <= "&(COLUMN()-1)*5&"
  label SUM(Col5)''")/
 QUERY({June2019!$M$3:$Z; July2019!$M$3:$Z; August2019!$M$3:$Z},
 "select COUNT(Col5) 
  where Col1 >  "&(COLUMN()-2)*5&"
    and Col1 <= "&(COLUMN()-1)*5&"
  label COUNT(Col5)''"), ))

或:

=ARRAYFORMULA(IF(ISBLANK(B27:27)=FALSE, 
 QUERY({June2019!$M$3:$Z; July2019!$M$3:$Z; August2019!$M$3:$Z}, 
 "select avg(Col5) 
  where Col1 >  "&(COLUMN()-2)*5&" 
    and Col1 <= "&(COLUMN()-1)*5&"
  label avg(Col5)''"), ))