Setting default date to Today with an option to set custom date in Tableau
Tableau is one of the best business intelligence and analytical tools out there to get insights about your data. It is very interactive and easy to use but it can be difficult to get some basic filtering to work. In a recent project I worked on, the client wanted to get metrics in a date range but wanted the dashboard and reports to default to today’s date. Tableau doesn’t have this feature built in.
Tableau does have date filters that are great and in most scenarios, those should suffice however in my case I needed the workbook to display metrics for current date by default and give the user an option to choose from a custom date range. Here is a how I did it.
The solutions consisted of:
- 3 parameters (the type of date to select, Start Date and End Date)
- A calculated field to be used as a filter.
First, Lets start with creating a list parameter titled “Date Type” with a data type of string and the list of values of Today and Custom Date. Set the Current value to “Today”
We then create 2 additional parameters for “Start Date” and “End Date” with a data type of Date, Display format to Automatic and Allowable values to All. These parameters will give the user the ability to select the date range.
Now that the parameters we need have been created we need to add the functionality so that the data displayed matches accordingly to the selected option a user chooses.
To do this we will create a calculated field called “Date Filter” it looks something like this:
The IF statement sets a filter condition based on the Date Type selected by the user. If the condition matches the result is a 1 otherwise it will display a 0. This calculated field will be created as a measure. Right click on the field and convert it to a dimension, drag it to the filter shelf and select 1 in the value
That’s it. Now go ahead and add the parameters to your report and the users will have the ability to select a date type for their reports and dashboards.
This is a quick solution to creating a date field that defaults to today in addition to giving an option to specify a custom date. Additional customization can be done to hide the Start Date and End Date parameters when Today is selected from the drop down.
Another application for this can be having preset time periods. For example you can add YTD, MTD WTD values in the date type parameter and when YTD is choosen the dashboard displays a comparison between YTD this year vs last year.