首页 文章

在Google Data Studio上的情况

提问于
浏览
1

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

  • 我是否需要指定两个日期之间差异的度量标准(就像我在BigQuery上做的那样)?

  • 我可以用数字命名值,而不是字符串(尽可能在BigQuery上做)?

  • 我是否需要将所有字段转换为日期格式,或者Data Studio是否将它们作为日期识别?

  • 我可以使用"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

1 回答

  • 2

    这是你的条件:

    (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)
    

    您可能需要各种强制转换才能使其工作,具体取决于基础列的类型 .

相关问题