I have a query that was originally hardcoded to pull 90 days prior to the current date, and nothing after the last business day on the previous month. However, I've been asked to change this hardcoding into date variables that users can select, but I want the default to be the coding below. Is this possible?
daterqst>= (CURRENT_DATE - INTERVAL '90 days')
daterqst <= (date_trunc('month', now())::date - 1)
Thank you for any help you can provide!
Hi @saaballergies
You can use Complex Default Value:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#setting-complex-default-values-in-the-query
daterqst>= [[{{start}} --]] (CURRENT_DATE - INTERVAL '90 days')
daterqst <= [[{{end}} --]] (date_trunc('month', now())::date - 1)
Or just Optional Clauses:
daterqst>= coalesce( [[{{start}},]] (CURRENT_DATE - INTERVAL '90 days') )
daterqst <= coalesce( [[{{end}},]] (date_trunc('month', now())::date - 1) )
Or use use Field Filters with default value with a relative date starting from previous month.
Hi, I'm trying to use a complex default filter for the field filter (date range) like this:
where [[ {{CreatedAt}} --]] (date_trunc('month', current_date))
It works fine when I select the date range but returns error when nothing is chosen
(ERROR: syntax error at or near "(" Position: 6251))
Do you have any idea?