While doing a customer case this week I stumbled across a view where I wanted to implement a certain style of “buttons” which are really useful in mobile apps, but that I didn’t know how to implement in Tableau.
With some really needed guidance and a lot of trial and error I came up with this:
A view with 2 or more “upper buttons” that will filter the view results. Depending on the button clicked, the button will be highlighted and the resulting view will be filtered accordingly.
These kinds of button selections are really useful (especially when the list is made out of 2 options) because the underlining and the color spotlight draw a clear conclusion about the option currently selected by the user.
How do you create this on Tableau? Let’s start!
As a first step let’s create a parameter that will help us with the selection. This parameter called [Selection Parameter] has nothing relevant but the data type, which is the same as my [Category] data type, which is the dimension I want to filter.
Then we create a boolean calculated field named [Category Highlight] that will tell which [Category] has been selected
Then you create a worksheet with the following:
- [Category] on Columns and Text
- [Category Highlight] on Color
- Entire View selected
- Select colors on [Category Highlight] that are contrasting
You apply this selection filtering into a relevant worksheet (in this case the Sub-Categories are filtered by Category based on the ‘Product’ hierarchy) by applying the [Category Highlight] into the filter and selecting True.
Once you have your 2 worksheets, you can put them in your dashboard and you can already have an initial view of your selection filter “buttons”
For the data to be filtered you should add a dashboard parameter action with the following:
- Source Field: [Category]
- Target Parameter: [Selection Parameter]
What this means is that: if the [Category] field is selected, the [Category] value will be placed in the your [Selection Parameter] parameter. Once your parameter has a value, your [Category Highlight] function will contain an boolean list that will let you know which actual [Category] is selected, which you can use in your view filters.
To make the underlining of the buttons we will create a worksheet with the following:
- [Category] on Columns
- Calculation: MAX(1) on Rows
- [Category Highlight] on Colors
- Entire View selected
Now add this worksheet into the existing dashboard below the [Category] buttons
To this worksheet we will need to remove the inner and outer padding
and edit its height to a really low number, like 5 pixels. Making it an underlining for the [Category] buttons
And now you have your dashboard with “clickable buttons”.