How to dynamically set default values for quick filters
Can we set a default value for a quick filter based on an action? Don’t be too quick to say “No!” That was my first inclination. But I was wrong; there is a way!
Note: The following is a guest post by Tableau Zen Master Joshua Milligan.
Recently, I was helping someone with a Tableau dashboard in which an action from the first view filtered a second view. The second view additionally had a quick filter, and that quick filter was set to show only relevant values. It worked something like this:
But try setting the drop-down quick filter option to “Medium” and then select “Express Air". Notice that “Medium” never occurs with “Express Air". The result is all data filtered out; a blank view is displayed. And the drop-down filter shows “(Medium)” – it’s in parentheses to let you know that the filter value isn’t relevant.
And I can confirm that with a quick view:
Indeed, not all Ship Modes use all Order Priorities.
The question arose: Can we get the quick filter to default to a certain value based on the Ship Mode selected? That is, can we set a default value for a quick filter based on an action?
Don’t be too quick to say “No!” That was my first inclination. But I was wrong; there is a way!
And I’ll tell you next time…
Just kidding! I’ll tell you now.
Setting default values for quick filters
Let’s say I identify the following values that I want for the defaults of the quick filter drop-down based on my selection:
Here are the steps I took:
1. Create a field that gives me the default order priority for each Ship Mode. I could do this in the source. I chose to do this as a row-level calculation. It’s important that it’s row-level and not aggregate, because I’ll need the field to be classified as a dimension (so no blending for the default, either).
2. Make sure the field is in the view that will trigger the action. Here, I’ve just added it to the detail of the Marks card:
3. Then create a new, separate action in the dashboard that maps Default Order Priority from the source sheet to the Order Priority field of the data source for the target:
(Notice that I’ve specified the target filters to specifically map the Default Order Priority to the Order Priority.)
After triggering the actions on the dashboard, you can look at the target view sheet and see that the actions are applied as filters:
So, the final trick to dynamically set and change the quick filter value is to use the action filter as a quick filter instead of the original field.
To do this, locate the little drop-down caret and use the menu to add the quick filter for the action:
And now, you have a dynamic quick filter with default values based on the selection! Experiment below: