与Google Data Studio连接的Google表格文件的示例:
Fruit |Color |Period |Amount
------------------------------
Apple |Green |201901 |3
Apple |Green |201902 |5
Apple |Red |201812 |5
Apple |Red |201903 |4
Grape |Red |201902 |4
Grape |Purple |201902 |6
Grape |Purple |201903 |1
例如,我想计算绿色和红色苹果果实的总量。
因此,公式应为:SUM Amount WHERE Fruit =“ Apple” AND Color =“ Green”或Color =“ Red”。在此示例中,总金额应为17
我试图在计算字段中使用此公式,但不幸的是,它不起作用:
SUM (Amount) WHERE (CASE WHEN Fruit = "Apple" AND Color = "Green" OR Color = "Red" ) then 1 else 0 END )
我收到语法错误。我该怎么解决?
答案 0 :(得分:1)
可以使用下面的CASE
语句来实现(可以选择所需的汇总,例如,平均值,总和,计数等)
CASE
WHEN Fruit = "Apple" AND (Color = "Green" OR Color = "Red") THEN Amount
ELSE NULL
END
Google Data Studio Report进行演示,以及使用图表级公式显示以下过程的GIF:
答案 1 :(得分:0)