Default range for date range filter in tableau

ぃ、小莉子 提交于 2019-12-10 19:19:13

问题


I want to set the default range on a date filter to show me the last 10 days - so basically looking at the lastDate (max date) in the data and default filtering only on the last 10 days (maxDate - 10)

How it looks now:

I still would want to the see the entire range bar on the dashboard and give the user the ability to modify the selected range if he wants to. The maxDate changes after every data refresh so it has to be some sort of a condition that is applied to the filter.

How I want it to look (by default after every refresh of data - new dates coming in):

Any suggestions on how this can be done? I know I can use the relative date and show the data for last 10 days but that would modify the filter and create a drop down which I don't want.

Any suggestions are welcome!


回答1:


One simple approach that does most of what you want is the following:

  1. Create an integer valued parameter with a range from 1 to some max you choose, say 100. Call it say num_days.
  2. Show the parameter control on your dashboard as a slider, and give it a nice title like "Number of days to display"

  3. Create a boolean calculated field called Within_Day_Range defined as:

    datediff('minute', [My_Date_Field], now()) < [num_days] * 24 * 60

  4. Put Within_Day_Range on the filter shelf and select the value true.

This lets the user easily select how many days in the past to include, and works to the granularity of minutes (i.e. the last two days really means the last 48 hours, not starting at midnight yesterday). Adjust the calculated field if you want different behavior.

The main drawback of this approach as described so far is that it doesn't display the earliest date possible in the database because that is filtered out. Quick filters do an initial query to get the bounds, which has a performance cost -- so using the approach described here can avoid that query and thus load faster.

If you really need that information on your dashboard, you could create a different worksheet to get just the min([My_Date_Field]) and display that near your parameter control.



来源:https://stackoverflow.com/questions/23807304/default-range-for-date-range-filter-in-tableau

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!