在 Data Studio 公式中使用 WHEN 和 CASE

using WHEN and CASE in Data Studio formulas

我习惯用 JavaScript 写作,所以我正在考虑 SWITCH 语句,当然还有经典的 if else...

我只想检查一行中的数据是否为真,是否为真。如果该值不正确,请不要将其添加到计数中。

我认为这样的方法可行:

CASE

WHEN is_it_true_or_false = false

THEN COUNT_DISTINCT ( id ) //using id to address that specific row and add it to the count

END

可以通过使用以下任一方式实现 CASE statements and aggregating the Calculated Field as required - COUNT_DISTINCT (Unique IDs of TRUE values) or COUNT(所有 TRUE 值):

1) 其中 is_it_true_or_false 是布尔或字符串字段:

CASE
  WHEN REGEXP_MATCH(is_it_true_or_false, "((?i)TRUE)") THEN id
  ELSE NULL
END

2) 其中 is_it_true_or_false 是布尔字段:

CASE
  WHEN is_it_true_or_false = TRUE THEN id
  ELSE NULL
END

Google Data Studio Report和GIF详解: