I am trying to use Templated Filters logic in LookML to filter a look/dashboard based on flexible dates i.e., whatever date value the user enters in the date filter (transaction_date_filter
dimension in this case). This is my LookML:
view: orders {
derived_table: {
sql:
select
customer_id,
price,
haspaid,
debit,
credit,
transactiondate,
case when haspaid= true or cast(transactiondate as timestamp) >= date_trunc(cast({% condition transaction_date_filter %} cast(transactiondate as timestamp) {% endcondition %} as timestamp),year) then debit- credit else 0 end as ytdamount
FROM
orders ;;
}
dimension: transaction_date_filter {
type: date
sql: cast(${TABLE}.transactiondate as timestamp) ;;
}
}
I get this error:
Invalid cast from BOOL to TIMESTAMP
Below is the rendered BQ SQL code from the SQL tab in the Explore when I use the transaction_date_filter
as the filter,
select
customer_id,
price,
haspaid,
debit,
credit,
transactiondate,
case
when haspaid = true or cast(transactiondate as timestamp) >= date_trunc(cast((cast(orders.transactiondate as timestamp) < (timestamp('2025-08-04 00:00:00'))) as timestamp), year)
then debit - credit
else 0
end as ytdamount
from
orders
Can someone please help?
CASE
statement logic.WHEN haspaid = true or A >= B < C THEN ...
I am not sure this is a valid syntax. I would break it into 3WHEN
conditions 1.WHEN haspaid = true THEN ...
2.WHEN cast(transactiondate as timestamp) >= ... THEN
and 3.WHEN ... THEN ...
That is easier to follow. If the first condition isn't met then try condition 2. If still not met, try condition 3. Easier to follow and debug.