One key data filter for almost any Tableau dashboard is to be able to filter by date ranges to see how metrics change over time. Business users are typically given a lot of freedom when it comes to filtering by dates and this often leads to two users thinking they are looking at the same timeframe, but are actually looking at different timeframes. One way to avoid this confusion is to create standard date filter buttons that allows users to select a predetermined date range. In this blog I will go over the steps to create these date filter buttons driven by parameter actions.
How to Implement Parameter Actions to Change Date Ranges in Tableau
The first step in this process is to create a data connection to a csv that has the number of date range options that are needed. In this example I want to have 6 options for the users to select from; This Week, This Month, Last 30 Days, Last 90 Days, Last 12 Months, & Custom Date Range. So the csv I am connecting to will have one column of data ‘Values’ with 6 rows of data 1-6.
Next, I am creating the parameters needed. This first parameter needed is the [Date Ranges] parameter as seen below. This is going to be used as the target parameter in the parameter action that will drive the filtering of the dashboard based on the user selection.
The next two parameters are [First Date] & [Last Date] that will be used in the Custom Date Range. These parameters are created in the same way shown below:
Calculations for Buttons
[Selected Date Range T|F]
Creating Button Sheet
To create the button sheet we need to first add a MIN(1) to the columns shelf. Add [Date Labels] to the rows shelf. On the marks card drag [Selected Date Range T|
F] to color. Drag [True], [False], & [Values] to details. Drag [Date Labels] onto text. The marks card should look like this:
Next we want to fix the axis from 0 to 1 so that the bars take up the whole width of the visual. We then want to sort the [Date Labels] in ascending order of the [Values] field to have them in order of the parameter [Date Ranges]. After sorting the visual we then want to hide the row header so that the labels are shown only inside the individual bars. Format the labels to appear in the middle center of the bar and edit the colors from the Tableau defaults.
Additional Data Source Calculations
The next step is to create two additional calculations in the non values.csv data source that the workbook is connected to. In this example we want to make sure the calculations are living in the Sample – Superstore data. The two calculations are [Date Filter] & [Max Date].
The case statement in the [Date Filter] calculation creates a boolean for each of the values in the [Date Range] parameter based on the text description associated with each of the parameter values (this week, this month, etc.). The last line in the case statement incorporates First Date & Last Date parameters to account for a custom date range that the users can manually select. The [Max Date] calculation creates a global max date of the data set. The date included in the [Max Date] calculation should be the date field used in the trending charts to align the filtering of the dashboard with the selection of the Date Ranges. Apply the [Date Filter] calculation to the appropriate sheets and select True as the only value to be kept (uncheck False).
Putting it all Together
Once the [Date Filter] is applied to the appropriate sheets we then want to next add the button sheet to the dashboard. Once that worksheet is added we can then create the necessary dashboard actions. We are going to add a parameter and a filter action to the dashboard. The parameter action should be created with the source sheet on Buttons (values) selected with the Run action on: Select selected. The parameter affected is # Date Ranges. The field is # Values (values) and aggregation should be set to minimum. We want to clear the selection to keep the current value. Below is the summary of what the parameter action should be:
This parameter action updates the parameter based on the value associated with the Date Label. This link was created with the [Date Filter] and [Date Label] calculations. When the user clicks on one of the bars with the labels the parameter will update with the associated value.
The last step in this process is to add a filter action to automatically deselect the mark on the bar chart when the user selects a new date range. Check out Luke’s blog post on the steps for how to do this. The filter action should look like this:
This standardized way of filtering trending data by predetermined date buckets is a great way to align business users to ensure they are looking at the same range of data and clearing up any confusion regarding this.