Google表格查询公式中的数据列

时间:2020-10-18 20:47:01

标签: if-statement google-sheets google-sheets-formula array-formulas

我要做的是创建一个查询公式,该公式返回按商店过滤的周数返回的年销售额。

示例工作表:Link

使用这样的公式很容易:=Query(query(A:D,"Select A,Sum(D) where A is not null group by A Pivot B",1),"Select * offset 1",0)

但是我还需要根据特定商店(Col C)过滤结果

这也不难: =Query(query(A:D,"Select A,Sum(D) where C = 'First' AND A is not null group by A Pivot B",1),"Select * offset 1",0)

但是在这种情况下,任何一周的销售和存储等于0的星期都将被错过。

我想显示数据中显示的所有星期(Col A)。有可能吗?

1 个答案:

答案 0 :(得分:2)

尝试:

=ARRAYFORMULA(QUERY(QUERY({A:B, IF(C:C<>"First", {"First", 0}, C:D)}, 
 "select Col1,sum(Col4) 
  where Col3 = 'First' 
    and Col1 is not null 
  group by Col1 
  pivot Col2"), "offset 1", 0))