【问题标题】:Google sheet Query Function Returns blank result from cell with data谷歌工作表查询函数从单元格返回空白结果和数据
【发布时间】:2015-04-19 20:57:00
【问题描述】:

我正在为我的工作场所创建一个电子表格,用于查找我们使用的 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

【问题讨论】:

  • 链接的文件不存在。

标签: google-sheets google-query-language


【解决方案1】:

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-2 或 2-4 结果的末尾添加了 &" ",现在它可以正确显示了。谢谢你的帮助!
【解决方案2】:

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

TO_TEXT() 将删除范围内的标题值,因此您需要使用虚拟列标题 Col1 和 Col2 而不是 QUERY(A:B, "SELECT B WHERE A = 'this one'")。 ARRAYFORUMLA(QUERY(TO_TEXT(A:B), "SELECT Col2 WHERE Col1 = 'this one'"))

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多