【问题标题】:Using Arithmetic Operators for null values in GSheets Query Function在表格查询函数中对空值使用算术运算符
【发布时间】:2022-11-04 21:35:27
【问题描述】:

但是,如果要在查询函数中聚合总计,Col2 和 Col3 中有空值,则总计值会导致空值。如何将查询函数中的空值替换为零值以允许算术运算符计算正确的结果?

=Query(QUERY(sampledata,"select D, COUNT(C) where A = 'Supplied' AND M = 'Recommended' group by D pivot B order by D"),"Select Col1,Col2,Col3,Col3+Col2, (Col2/(Col3+Col2)) label Col3+Col2 'Total', (Col2/(Col3+Col2)) 'Action Rate' 格式 Col1 'dd-mmm-yyyy', Col2 '#,##0', Col3 '#,##0', Col3+Col2 '#,##0', (Col2/(Col3+Col2)) '#,##0.0%'")

尝试使用普通 SQL 函数,如 ISNULL 和 COALESCE

合并(Col3,0) ISNUL (Col2, 0)

但是,这些在表格中不起作用。

【问题讨论】:

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


    【解决方案1】:

    像这样修改你的公式

    =ArrayFormula(Query(QUERY(IF(sampledata="Null",0,sampledata),"select D, COUNT(C) where A = 'Supplied' AND M = 'Recommended' group by D pivot B order by D"),"Select Col1,Col2,Col3,Col3+Col2,(Col2/(Col3+Col2)) label Col3+Col2 'Total', (Col2/(Col3+Col2)) 'Action Rate' format Col1 'dd-mmm-yyyy', Col2 '#,##0', Col3 '#,##0', Col3+Col2 '#,##0', (Col2/(Col3+Col2)) '#,##0.0%'"))
    

    将“Null”替换为 0,简化如下。

    IF(sampledata="Null",0,sampledata)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-23
      • 2021-06-23
      • 1970-01-01
      • 2014-03-20
      • 2021-08-11
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      相关资源
      最近更新 更多