Google sheet 查询函数 Returns 包含数据的单元格的空白结果

Google sheet Query Function Returns blank result from cell with data

我正在为我的工作场所创建一个传播sheet,它将为我们使用的 LED 找到驱动程序,但我 运行 遇到了一个小问题。我从另一个 sheet 中提取数据以将其细化,然后我有一个 sheet 用于公式,一个用于表格,数据本身 sheet。出于某种原因,我对一个 sheet 进行了计算,然后使用查询函数对 return 计算另一个 sheet 的结果,但结果有时会丢失数据。

我使用这个公式来确定有多少个 LED 可以连接到驱动器:

=IF(A4="","",IF(U4="Y",If(K4>1,IF(round(O4)=round(P4),P4&" per Channel",O4&"-"&P4&" per Channel"),IF(round(O4)=round(P4),P4,O4)),IF(U4="Min+1",If(K4>1,IF(round(O4+1)=round(P4),P4&" per Channel",(O4+1)&"-"&P4&" per Channel"),IF(round(O4+1)=round(P4),P4,(O4+1)&"-"&P4)),IF(U4="Max-1",If(K4>1,IF(round(O4)=round(P4-1),O4&" per Channel",O4&"-"&(P4-1)&" per Channel"),IF(round(O4)=round(P4-1),P4,O4&"-"&(P4-1)))))))

然后我使用这个函数来显示所有可用驱动程序的列表,但是上一个公式的结果,即使它显示在公式 sheet 上,也不会显示在表格 sheet.

=IFERROR(if($C="Y",if(BFFormulas!R1="CC",query(BFFormulas!A3:Z900,"select A,B,D,H,I,K,Q,L where A != '' and J='Y' and N = 'Y' order by D ",1),if(BFFormulas!R1="CV",query(BFFormulas!A3:Z900,"select A,B,D,H,I,K,Q,L where V > "&BFFormulas!T1*D3&" and A != '' and J='Y' order by D ",1),"Missing Fixture Information")),if(BFFormulas!R1="CC",query(BFFormulas!A3:Z900,"select A,B,D,H,I,K,Q,L where A != '' and N = 'Y' order by D ",1),if(BFFormulas!R1="CV",query(BFFormulas!A3:Z900,"select A,B,D,H,I,K,Q,L where V > "&BFFormulas!T1*D3&" and A != '' order by D ",1),"Missing Fixture Information"))),"Could Not Find Fixture From This Source.")

谁能告诉我为什么会这样?

发生的事情的图片: https://drive.google.com/file/d/0Bw6otjO0spyBd2NXYWhuQm1QbnM/view?usp=sharing

QUERY 会将具有混合数据类型的列转换为一种数据类型。如果数据主要是数值,那么文本字符串(例如数据中的 1-2)将被转换为空白单元格。

解决方法是将所有内容都转换为文本字符串(如果您可以接受其结果)。请注意 QUERY 函数中每个范围附加的 &""

=ArrayFormula(IFERROR(if($C="Y",if(BFFormulas!R1="CC",query(BFFormulas!A3:Z900&"","select A,B,D,H,I,K,Q,L where A != '' and J='Y' and N = 'Y' order by D ",1),if(BFFormulas!R1="CV",query(BFFormulas!A3:Z900&"","select A,B,D,H,I,K,Q,L where V > "&BFFormulas!T1*D3&" and A != '' and J='Y' order by D ",1),"Missing Fixture Information")),if(BFFormulas!R1="CC",query(BFFormulas!A3:Z900&"","select A,B,D,H,I,K,Q,L where A != '' and N = 'Y' order by D ",1),if(BFFormulas!R1="CV",query(BFFormulas!A3:Z900&"","select A,B,D,H,I,K,Q,L where V > "&BFFormulas!T1*D3&" and A != '' order by D ",1),"Missing Fixture Information"))),"Could Not Find Fixture From This Source."))

另一个好的解决方案是使用 TO_TEXT() 将混合数据类型列显式转换为字符串。 TO_TEXT() 无法在 QUERY() 函数内部单独运行,但由于您已经在使用 ARRAYFORMULA(),因此将查询范围包含在 TO_TEXT() 中可能有助于解决问题。

TO_TEXT() 将删除范围内的 header 值,因此您需要使用虚拟列 headers [= 而不是 QUERY(A:B, "SELECT B WHERE A = 'this one'") 17=] 和 Col2ARRAYFORUMLA(QUERY(TO_TEXT(A:B), "SELECT Col2 WHERE Col1 = 'this one'"))

来源:https://infoinspired.com/google-docs/spreadsheet/mixed-data-type-issue-in-query/