Tableau out of the box options for date filters are somewhat limited. When creating a report or dashboard, developers have to decide between absolute filters (e.g. show 2020-03-01 until 2020-05-04) and relative filters (e.g. show last 12 months from today). Though these options cover many simple use cases, we might often want to mix the two options: Setting a relative filter as default, while still allowing the user to select absolute periods.
A Solution Using Parameters
As an example, we’re creating a dashboard that always shows data from the last 12 months as its default view, but the users should also be allowed to filter data down to any custom period they are interested in. To accomplish that, we’ll introduce a parameter that will act like a switch between the default and custom behavior. For simplicity we can use the strings „Default“ and „Custom“ as values.
Now we can create parameters for the start and end date of the custom filter period. Make sure to select date as the data type.
We also need to create calculated fields that read the current value of our switch parameter and determine the start and end of the desired period.
Finally, we create a calculated field that returns true or false for each day of the date variable we want to use. In the Superstore sample dataset this could be the order date.
Now we can drag the newly created Date Filter to the filter box of our worksheet. We set the filter to only include „True“.
And we’re done! Our user can now decide to view data from the past 12 months or filter down to a specific period.
We hope you enjoyed this short Tableau tutorial on custom date filters. Please let us know if you have any questions by leaving a comment!