Question

Setting the current date as the default date filter

  • 3 August 2018
  • 5 replies
  • 5681 views

Hi.


I wish to create a look in which date is one of the filters. I know it is possible to set a certain date as the default value - this ensures that whenever that dashboard in opened, the filter is already populated with the default date.

However, I want the filter to automatically have the current date every time a user opens that dashboard. Is it possible to set current date as the default filter value?


Thanks,

Arish


5 replies

Looker’s ‘advanced filter’ syntax lets you represent pretty complex expressions in the advanced filters section of the explore. The most interesting of these are the date expressions. You can say things like ‘1 day’ or ’ 2 weeks’ or ‘monday for 3 days’.


https://docs.looker.com/reference/filter-expressions


I actually prefer conditionally filter because it requires that only one of the filter conditions is met. If you use a dimension_group, it requires only one of the dates from the dimension group be set.




So, putting it all together…


explore: orders {
conditionally_filter: {
field: orders.order_date
value: "1 day"
}
}

Thanks for your reply!

I’m not sure if I explained myself clearly in the previous post. Let me use an example.


“The dashboard/look contains a date filter. If a user opens the dashboard today (i.e., on August 6), the date filter automatically contains 06-Aug-2018. If the user opens the dashboard tomorrow, then the date filter automatically contains 07-Aug-2018.”


How can I achieve this?

I found the “today” option within advanced filters. This serves my use case.

Thanks a ton, @lloydtabb!

@arishojaswi, how did you pull this off? I’m trying to have a date range filter on my graph which always has the upper bound set to today’s date.

I wanted to implement as as_of_date via parameter that defaulted to today’s date.


The [relatively unstable] solution I discovered was to create the parameter in the view file, but also to have an empty always_filter for that parameter in the explore (empty being “”). Putting an empty default_value in the parameter definition didn’t work, and defaulted to NULL instead of to today’s date.


If the parameter was referenced inside a function in a derived table, it didn’t work (unclear why) – instead of using date_add(‘days’, -x, {% parameter as_of_date %}) I had to use {% parameter as_of_date %}::date - x


This seemed sort of like a happy accident that could change if always_filter changes how it handles empty filters for dates.

Reply