One of the features announced at Tableau Conference 2018 that I am most excited about is parameter actions. This feature will unlock a lot of flexibility that will provide better opportunities to design your user experiences and transfer control of an analysis from yourself to your end users. But did you know this feature is already available in the form of a Tableau dashboard extension called Parameter Actions?
In this post, I’ll be sharing one of my favorite ways to improve the user experience of a line graph by allowing users to choose which date part, or granularity, is being visualized (i.e. day, week, month, year). Then we’ll make that user experience even better by using Tableau’s Parameter Actions extension, which is available as of Tableau Desktop 2018.2. The dashboard extension will allow us to create a seamless, web-like experience that will allow our end users to change a date part by simply clicking on a letter!
Related video tutorial:
Premier Tableau eLearning from Playfair Data TV
How to allow your end users to set the date part of a Tableau line graph
Before I share the approach for allowing your end users to visualize graphs at different granularities, let’s look at why this tip is needed in the first place. Here is a line graph I made with the Sample – Superstore dataset that looks at Sales by Continuous Order Date.
This graph is challenging to read because, other than the spikes, it’s hard to compare the performance of individual days. To help me read the chart, I can change the date part, or granularity of the date, from day to month.
This is now much better when looking at my entire dataset of four years, but what if I now want to take a closer look at just one month of data?
Oops…. I see just one data point because my date part is month and there’s only one month in the view. I would prefer to have flexibility in which date granularity I’m using based on the number of dates being shown on the view. You’re able to drill down and back up in Tableau when fields are part of a hierarchy, including dates, by hovering over the axis and clicking the plus sign (to drill down to more granular date parts) or minus sign (to drill back up to less granular date parts) that appears.
However, I’ve never loved this user experience because the drilldown capability is very subtle, and depending on the audience I am designing for, they likely don’t know this feature exists. Not to mention that if there is more than one line graph, the user would have to change the date part for every chart individually. I could coach my end users to use this feature, but here’s a simple two-step tactic I often use to provide this user experience in a more intuitive way that also works across multiple line graphs.
First, set up a parameter with a data type of String and a list of allowable values. The allowable values will be the date parts that you want your end users to be able to choose from. For this example, let’s say we’ll eventually allow the end user to choose to look at the line graph by day, week, month, or year. To get this to work with the second step, it’s critical that the values are lowercase, but they can be displayed with whatever casing you prefer. Here’s how my parameter looks:
The second step is to set up a calculated field that truncates the date at whatever value is selected in the parameter from step one. The formula is:
DATETRUNC([Date Granularity],[Order Date])
Now if I replace the original Order Date with this newly created Date with Granularity calculated field, the date will be truncated by whatever is selected in the parameter. It’s critical to choose Date (Continuous) when using this calculated version of the date so it will work regardless of which date part is selected.
Note that the first allowable value in a parameter becomes the current value of the parameter by default. That’s why when I replaced Order Date with Date with Granularity, the line graph is broken up at the daily level. Now if I show the parameter control from the Date Granularity parameter by right-clicking on it and choosing “Show Parameter Control”, my end user can decide how the dates are truncated. For example, here’s how this same chart looks when Week is selected in the parameter control.
The underlying date part value is populating the Date with Granularity calculation to change how the line graph is being truncated – and it’s completely controlled by the user!
Using Tableau’s Parameter Actions extension to control date parts
The tactic I’ve described so far is something I’ve been using for a while, but it can be made even better with one of Tableau’s newest features, Dashboard Extensions. Extensions allow Tableau as well as third-party developers to take the core software a step further. In this case, we will use dashboard extensions to create a more friendly, web-like experience that allows our users to change the date part in the line graph.
Candidly, so far I’ve only used Tableau dashboard extensions published by Tableau themselves, including the extension needed for the approach I’m about to share: Parameter Actions. You can review the current list of available extensions and download them at https://extensiongallery.tableau.com/. You can save these extensions wherever you would like, but I recommend saving them in your Tableau repository or your Tableau program files.
For this tutorial, we’ll say that instead of having the end user use a dropdown menu to change the date part, we’ll allow them to change the date granularity by just clicking on letters that represent the date parts: D, W, M, Y.
The first step is to set up a control sheet with the ‘buttons’ that our end user will click on. To do so, I’ve connected to a second data source that includes just two columns: Button (the date part abbreviations) and Value (the lowercase date parts). I’ll then just make a text table that my user will eventually click on.
Note that I’ve placed the Value field on the Detail Marks Card. This field contains the words day, week, month, and year. It’s critical to have those values on the view because they’ll be needed to populate the Date with Granularity calculation later on.
There’s one more thing needed to get this to work which is to have your date granularity parameter have allowable values of all. Previously, we set this up with a list of specific allowable values, but now I will update the parameter to have allowable values of All. This eventually will allow the current value of the parameter to be whatever word is selected in the control sheet.
We’re now ready to create the user experience on a dashboard. First, place both the line graph and control sheet on a new dashboard. I’ve also removed the date filter from the line graph to display all of the dates in the Sample – Superstore dataset.
If you’re using Tableau Desktop 2018.2 or later, you will see a dashboard object called “Extension”. Drag that onto the view and find the extension you are trying to use (installation required); installed extensions end with the file extension .trex.
It doesn’t matter where you put this on the dashboard, because after we configure it, I’ll show you a trick for hiding it altogether. After placing the Parameter Actions extension onto the view, the configuration options will open. This is a fairly intuitive interface. In my case, I’ve told the extension that I’m using the Date Granularity parameter, I want the Value field to populate the current value of the parameter, and the selection originates on the sheet called Control Sheet.
Now if I click the M in the control sheet, the month date part value will populate the Date with Granularity calculated field that is truncating the dates.
If I click on the Y, it’s truncated by Year, and so on.
So this is working great, but obviously that gear icon and surrounding white space is taking up way too much room on the dashboard. To hide it, select the extension object by clicking on it (you’ll see a gray border appear), click the down arrow in the top right corner of the object, and click “Floating”.
Once the object is floating, click the Layout pane, and change its dimensions to 1 pixel by 1 pixel.
This makes this object invisible on the view. You can always find the object if you need to change its configuration by clicking on the Layout pane and clicking the name of the object at the bottom of the pane.
Here’s how my final view looks after hiding the Extension object, resizing the line graph to fill more vertical space, and choosing Week as the date part.
The end user can now control the granularity of the line graph by simply clicking a single letter from the control sheet at the top! This web-like experience can be rolled out across multiple charts on a dashboard to make it as easy as possible for your stakeholders to conduct their analyses.
Thanks for reading,