首页 > 解决方案 > Google Data Studio 上的案例

问题描述

我试图在数据工作室上创建一个使用“case when”和函数 Date_diff 的字段。我不断收到错误“无法解析公式”。

  1. 我是否需要指定两个日期之间差异的指标(就像我在 BigQuery 上所做的那样)?
  2. 我可以用数字而不是字符串来命名值吗(尽可能在 BigQuery 上做)?
  3. 我需要将所有字段转换为日期格式,还是 Data Studio 自己将它们识别为日期?
  4. 我可以使用“Between”功能吗?

我的最新版本(不起作用)如下:

case when date_diff(cast(checkin as date),order_date,day)>=0 and <=3 then 3

when date_diff(cast(checkin as date),order_date,day)>=4 and <=7 then 7

when date_diff(cast(checkin as date),order_date,day)>=8 and <=14 then 14

when date_diff(cast(checkin as date),order_date,day)>=15 and <=30 then 30

when date_diff(cast(checkin as date),order_date,day)>=31 and <=60 then 60

when date_diff(cast(checkin as date),order_date,day)>=61 and <=180 then 180

when date_diff(cast(checkin as date),order_date,day)>=181 and <=365 then 365

end

标签: sqlgoogle-bigquerygoogle-data-studio

解决方案


这是你的条件:

(case when date_diff(cast(checkin as date), order_date, day) >= 0 and <= 3 then 3
 . . .

这没有意义。您可以将其表示为

(case when date_diff(cast(checkin as date), order_date, day) between 0 and 3 then 3

我更倾向于把它写成:

(case when checkin >= order_date and checkin < date_add(order_date, interval 4 day)

根据底层列的类型,您可能需要各种强制转换才能完成这项工作。


推荐阅读