Hello,
I am using Metabase 0.33.4. How to set Current Date as Default filter widget value in Metabase Questions?
Hi @Suganesh
I’m guessing you’re talking about filters in Native/SQL? There’s a request open for it:
https://github.com/metabase/metabase/issues/4509 - upvote by clicking on the first post
But you can use Complex Default Values to do that:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#default-value-in-the-query
Hi @flamber
Thank You for the Quick Response.
Hi @flamber. Is these a way to set the default date to today’s date with Amazon athena? I tried it using # and current_date() but it gives me error.
@shubham-mt Looks like it’s not a function, just a reserved word, so try with current_date
:
https://dba.stackexchange.com/questions/171614/how-to-get-the-records-from-amazon-athena-for-past-week-only
@flamber I tried this [[AND CAST(media.timestamp AS DATE) BETWEEN {{start_date}} AND {{end_date}}#]] current_date. This is still giving me error. Is this the right syntax?
- You need to post the error.
- I have no idea what you’re actually trying to do, so please explain that
- You cannot use multiple variables in the same optional clause:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html - Perhaps you should use Field Filter instead?
@flamber I was trying to apply date range filter with default values as last 7 days (was trying to give default values with the way mentioned above). However now I have used Field Filter and used date filter within it to give default values. Thank you
You can use this as reference
"your
_variable" >= coalesce([[{{Startdate}}::date,]] current_date - '1 WEEK'::interval) AND
"your
_variable" <= coalesce([[{{EndDate}}::date,]] current_date ) and
suppose you have two filters Startdate and Enddate
what these statements will do is set startDate as (current date - 1week ). you can change week to month , year etc.
and end date as today's current date.
But if you choose some dates from the filter , it will consider that dates in place of default dates you have provided.
you should try the default value for filter like this:
startDate >= [[{{from_date}} --]] CURDATE()
here if you don't choose a value for the {{from_date}} filter, its value will be the current date by default. please notice the -- (cause it is the symbol used to comment in your query language), it may change base on your query language.
I think this is Allow relative dates for default values in SQL variables · Issue #4509 · metabase/metabase · GitHub
@cmn_0211 this solution was genius!
It worked for me! Thank you very much!
@Aphonso you're welcome. glad to help metabase users