- Robert Crocker
This post was inspired by the frequent client request to have a menu of quick date presents + a custom date picker. Of course, these features are easy enough to create in isolation but challenging to pull off in a way that makes preset options and custom date range available at the same time without confusing the user.
Until version 2019.2, creating a way for people to select preset time periods (3M, YTD, 6M, 1Y, etc) while also being able to select custom date ranges, without having the two options conflict was a hassle! Thankfully, we no longer need to create complex configurations of separate worksheets tied together with dashboard actions or limit our users to the inflexibility of parameter formatting options. Now, with the release of parameter actions we can easily and quickly create filters that look however we want.
In this tutorial we’ll create a dropdown for your clients, colleagues, or side projects, using Tableau’s parameter actions.
Step 1: Create the chart you will eventually be filtering
For this example, we’re using Superstore data, putting together a very simple line chart for Sales over time, in a sheet we’re calling Chart
If you want a chart just like the one you saw in the introduction GIF, then be sure to change the mark type to bar.
Step 2: Create a data source to serve as your labels
First off, this idea of using a separate data source to drive our parameter actions was first inspired by Ryan Sleeper. This allows us to create labels exactly how we like them in a separate data source.
Once connected to your data source you’ll want to make sure to sort your labels.
Step 3: Create the dropdown list
These controls were inspired by the Tweet from @datavizlinds. With the Date Range Control data set selected, create a new sheet that we’ll name Date Buttons. In order to make this step work, we’ll need to create a calculation for the Bullet and the Custom Color. Don’t worry, they’re simple.
-- Bullet IF [Label] = [Date Parameter] THEN '●' ELSE '○' END
You can find the Unicode characters above at w3schools.
Make sure you set the Label Color to be continuous.
With those calculations created we can create the dropdown list.
I know it doesn’t look like much yet, but this configuration will make more sense once it’s added to our dashboard.
Step 4: Create the parameter to capture your selection
Clicking the arrow at the top of the data pane and create a parameter.
Because our parameter just needs to hold the labels we select we can leave it blank for now. Be sure to set the data type to string.
Step 5: Create the calculations that will filter our data range
In your Chart sheet, select the arrow on the sidebar and create the calculated fields that will define your date ranges. In our example, we’re creating 7 different customized periods: 1 Month, 1 Year, Q1, Q2, Q3, Q4 and a Custom option. If you’re not familiar with Date formulas in Tableau, this link might help. And yes, these calculations won’t return great results in the new year (2020), so please modify them to your liking.
-- 1 Month [Date] > DATEADD('month', -1, TODAY())
1 Year DATEPART('year', [Date]) = DATEPART('year', DATETRUNC('year', TODAY()))
-- Q1 DATEPART('quarter', [Date]) = DATEPART('quarter', DATETRUNC('year', [Date]))
-- Q2 DATEPART('quarter', [Date]) = DATEPART('quarter', DATEADD('quarter', 1, DATETRUNC('year', [Date])))
-- Q3 DATEPART('quarter', [Date]) = DATEPART('quarter', DATEADD('quarter', 2, DATETRUNC('year', [Date])))
-- Q4 DATEPART('quarter', [Date]) = DATEPART('quarter', DATEADD('quarter', 3, DATETRUNC('year', [Date])))
-- Custom [Date] >= [Start Date] AND [Date] < [End Date]
Note that the Start Date and End Date are parameters too - more about how this is done on step 7. If you’re new to parameters altogether, here’s an article describing how they’re created in more depth.
After all of the calculated fields are set up, create a master calculation wrapping them all up with a calc called Date Filter.
-- Date Filter CASE [Date Parameter] WHEN '1M' THEN [Date - 1M] WHEN 'Q1' THEN [Date - Q1] WHEN 'Q2' THEN [Date - Q2] WHEN 'Q3' THEN [Date - Q3] WHEN 'Q4' THEN [Date - Q4] WHEN '1Y' THEN [Date - 1Y] ELSE [Date - Custom] END
Drag the Date filter to the sheet’s filters card, and set the filter to True.
Step 6: Assemble the dashboard & assign the parameter action
If you have never used Figma or any other tools to create custom background images, then this step might feel a little magical. The devil is in the details. Again, don’t worry, I’ll create a video and GIFs of the most important parts so that you can get the concepts and adjust it to your needs.
Let’s first create the container the appears and disappears when the arrows are selected.
Now that we have our dropdown in place we can wire up the parameter action.
Step 7: Automatically deselect the marks
This step is a compound shout out that you can walk through on the Tessellation website. Without this step our simple dropdown doesn’t look nearly as nice.
So, let’s wrap this up with a bow by with the concept @lukestanke summarized @jonathandrummey introduced and @yurifal improved upon.
Mmm, that feels much better. No need to reselect anything to get the dropdown list back to a state where it look like… well… a dropdown list.
This post puts you among a small group of people able to create beautiful, custom controls with Tableau. Of course, there’s much more you can do with parameter actions besides these simple date ranges. This article is just the start of your custom creations! I look forward to seeing what you create to make the experiences of your user more pleasant and interesting.
If you’d like to watch the full video of these controls being created while I talk through each step be sure to subscribe.
Big thanks to Thabata for all the help prepping this post. Say hey to her on LinkedIn. She’s recently gone freelance herself 😎