One of the best ways to take a dashboard to the next level is to incorporate interactivity beyond what’s available out of the box in Tableau. One example of this is Tableau button swapping, which allows the use of images to filter marks on a view with separate images for the selected and unselected states of each button. Previously, Ryan shared a post on button swapping utilizing set actions. Today, I’ll walk you through creating the same functionality – but this time using parameters.

How to Show Selections with Button Swapping in Tableau

 

How to Do Button Swapping with Parameters in Tableau

View / Interact / Download

 

Set up your images for button swapping in Tableau

By the end of this post, you’ll be able to set up button swapping using parameters for your own dashboard. My example uses images sourced from The Noun Project and the World Indicators dataset from Tableau, but you can use any images and data source you like to follow along. I decided to filter population data by region, so I chose a filled in image to represent a selected region and an outline image to represent an unselected region. 

Source and set up your images for button swapping in Tableau

Once you’ve sourced your images, save them to the following location on your computer: Documents > My Tableau Repository > Shapes. Either save your images in an existing folder, or create a new folder and give it a name relevant to your project. I saved my images under a folder named “Geography”.

Join 25K+ leaders using Playfair Data to make better decisions.
 

This field is for validation purposes and should be left unchanged.

 

Set up parameter and calculated fields for button swapping in Tableau

To set up the infrastructure of this interactivity, we’ll first set up a parameter. Later on, we’ll use this parameter to set up a dashboard action that will allow us to click a button, swap images to represent a selected state, and filter the dashboard on that dimension. To do this, I’ll right-click on the Region dimension, hover over “Create”, and choose “Parameter”. 

string parameter setup

I renamed my parameter “Focus Region”, but choose whatever name makes sense to you. Everything else in the parameter settings will remain as is. 

Next, I set up two calculated fields. The first is a Boolean calculation that checks whether or not a region equals the parameter selection. This Boolean calculation will be placed on the Filters shelf of any visual that the buttons will control. The logic is as follows:

[Region]=[Focus Region Parameter]

filter boolean calculation

The second calculation creates the button-swapping effect. Since only one Region can be selected at a time with the parameter, I’ll use this on the Shape property of the Marks Card to denote a selected or unselected Region by assigning the custom shape palette accordingly. Here’s the logic:

[Focus Region Parameter] = ‘Selected region’

button calculated field logic

Duplicate this calculation once for each dimension member in the Focus Region parameter.

 

Set up your control sheet

Now we’ll set up our control sheets that will contain our buttons and can be used to filter our dashboard. Create a new sheet and set the Mark type to Shape. Drag the corresponding calculation onto the Shape property of the Marks card.

Adding boolean calculated field to Shape Property

Double-click into the Marks Card to type in the relevant dimension member from the Focus Region parameter, between single quotes. This will automatically add ‘Region’, or in this case, ‘Africa’, to the Detail Property of the Marks Card. This is essential for the button-swapping dashboard parameter actions later on.

adding region in quotes to Detail Property

Tableau will choose the default shapes for our buttons, so next we need to map our custom shapes to the correct dimension members in our view. To do this, click Shape on the Marks card and select the custom shape palette you created. If you already had Tableau open while you created your shape palette, click “Reload Shapes” and your palette will appear in the dropdown. Show the parameter control on your sheet and swap through each value in the parameter to map all of the selected and unselected state images.

Repeat this process for the other regions within the Focus Region parameter.

Here’s what the Button_Africa sheet looks like with all my shapes mapped and Africa selected:

_button africa is true


Learn to navigate uncharted waters.

Upgrade to Core or Premium benefits to take your data skills even further.

 

Create your dashboard and add interactivity

The final step in this process is to add the control sheets to the dashboard in a horizontal container and set up one parameter action per control sheet to create the interactivity. Click “Dashboard” and then “Actions” from the toolbar at the top of the screen. Click “Add Action” and choose “Change Parameter”. For your source sheet, pick your control sheet, and run the action on Select. Select your target parameter, in my case it’s called “Focus Region”, and add your source field, which for me is the selected Region in single quotes.

create parameter action

Here’s what my final dashboard actions menu looks like, with one action per control sheet:

Final dashboard actions menu

Behind the scenes, Tableau is checking the dimension member in the selected control sheet against the current value in the Focus Region parameter. This swaps the button image you see as you change the highlighted dimension member with each click. Additionally, as you click through the buttons on your control sheet, the other views on your dashboard will filter as well. Voila, button swapping with parameters!

How to Do Button Swapping with Parameters in Tableau


Happy vizzing,

Alyssa

Become a member

Get access to this related video & more!

Become a Member

Related Content

Ryan Sleeper

Data source filters > context filters > dimension filters > measure filters See how the different types of Tableau filters…