Google表格查询功能从包含数据的单元格返回空白结果

时间:2015-04-19 20:57:01

标签: google-sheets google-query-language

我正在为我的工作场所创建一个电子表格,找到我们使用的LED的驱动程序,但我遇到了一个小问题。我从另一张纸上拉出数据以稀释它,然后我有一张公式表,一张表格,以及自己表格上的数据。出于某种原因,我在一张纸上进行计算,然后使用查询功能将该结果返回到另一张纸上,但结果有时会遗漏数据。

我正在使用此公式来确定可以将多少个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)))))))

然后我使用此功能显示所有可用的驱动程序列表,但上一个公式的结果,即使显示在公式表上,也不会显示在表单上。

=IFERROR(if($C$3="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

2 个答案:

答案 0 :(得分:0)

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

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

=ArrayFormula(IFERROR(if($C$3="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."))

答案 1 :(得分:0)

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

TO_TEXT()将摆脱该范围内的标头值,因此,您需要使用虚拟列标头QUERY(A:B, "SELECT B WHERE A = 'this one'")Col1来代替Col2ARRAYFORUMLA(QUERY(TO_TEXT(A:B), "SELECT Col2 WHERE Col1 = 'this one'"))

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