首页 > 解决方案 > 如何在 QUERY 的第二个参数中使用多个 TEXT 函数?

问题描述

在第二个参数中使用Query带有text()orTo_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“”。期待以下之一:“(”...“(”...

任何帮助,将不胜感激

标签: google-sheetsgoogle-sheets-formulaarray-formulasgoogle-sheets-querygoogle-query-language

解决方案


尝试:

=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)''"), ))

推荐阅读