Reputation: 39
Im trying to create a field on data studio that uses a "case when" and the function Date_diff. I keep getting the error "Could not parse formula".
My latest version (which isn't working) is the following:
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
Upvotes: 1
Views: 2849
Reputation: 1269803
This is your condition:
(case when date_diff(cast(checkin as date), order_date, day) >= 0 and <= 3 then 3
. . .
This doesn't make sense. You can express this as
(case when date_diff(cast(checkin as date), order_date, day) between 0 and 3 then 3
I would be more inclined to write this as:
(case when checkin >= order_date and checkin < date_add(order_date, interval 4 day)
You might need various casts to make this work, depending on the types of the underlying columns.
Upvotes: 2