This is the third and final post in a series about toggles in Tableau. For other applications, see the easy way to make a toggle and how to make an integrated toggle switch.

One night at a team happy hour, someone proclaimed, “If we’re going to make a toggle, let’s make America’s best toggle,” and the following user experience was born. By the way, if this sounds like a conversation you wish you were a part of, we’re hiring.

This post shows you how to toggle on a selection from two or more choices with the click of a button. The innovation is that a unique image will be swapped in to highlight the current selection.

Watch the related video with Playfair+

 

How to use button swapping to create a better Tableau toggle

By the end of this post, you will be able to make a field selector that highlights the current selection.

How to make a Tableau toggle

Admittedly, I am taking some liberty with the definition of “toggle” in this example, which is typically thought of as toggling between exactly two features (i.e. a Play / Pause button). I think of the experience outlined in this post as a toggle because you can only toggle one thing on at a time and it’s either the selection or it isn’t (i.e. Boolean). Of course, you can also create this experience for only two options.

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

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

To create the selector user experience, we will use a technique called button swapping. Button swapping was developed when set actions existed, but parameter actions did not, so this tutorial will be slightly different. Parameter actions vary from set actions in that (1) something always has to be selected and (2) you cannot do a multi-select; making it a perfect option for a single select “toggle”.

First, create two images for each option: a selected version and an unselected version. For best results, the images should be the exact same dimensions and be created as PNG file types with transparent backgrounds. If you’re able to make the backgrounds transparent, you can place the toggle on a background of any color.

Tableau toggle images

Add these images to a palette folder (or create a new one) in your Tableau Repository at Documents > My Tableau Repository > Shapes.

Add these images to a palette folder (or create a new one) in your Tableau Repository

In Tableau Desktop, create a string parameter with your toggle choices.

Toggle Choice Tableau Parameter

If the choices are not in an existing dimension, you are likely better off creating a separate data source in Excel containing your toggle choices.

How to Use Control Sheets for Better Parameter Actions

Next, create one control sheet for each dimension member in the Toggle Choice parameter. These control sheets serve as buttons in a dashboard that change the parameter value when they are toggled.

One control sheet per dimension

Now here is the formula that makes this whole technique go. We’re going to classify each toggle choice as either matching the parameter selection or not matching the parameter selection with one Boolean calculated field for each toggle choice. The formula is:

[Toggle Choice Parameter] = ‘Dimension Member to toggle’

calculated field for Toggle Choice

To map the custom images, change the mark type of your control sheet to Shape and place this newly created classification calculated field on the Shape Marks Card. Map the classification field to the custom images we placed in our Tableau Repository by clicking the Shapes Marks Card or double-clicking any image on the Shape legend.

mapping classification calculated field to shape property

Double-click into the Marks Card to type in the relevant dimension member from the Toggle Choice parameter, between single quotes. This will automatically add ‘Dimension member’, or in this case, ‘Furniture’, to the Detail Property of the Marks Card. This is essential for our dashboard parameter actions later on.

marks card of the furniture toggle worksheet

To ensure you’ve mapped every possible outcome, show the Toggle Choice parameter control by right-clicking the parameter from the Parameters area of the Data pane and choosing “Show Parameter Control”. You can now easily change the current value of the parameter and finish mapping your custom images.

remapping the True shape for furniture toggle

Repeat this process for the other dimension members in the Toggle Choice parameter.

This sheet is now ready to control the selection for any sheets on a dashboard. As one example, I’ll make a sales-by-month line graph. The key is anytime you want the filtered results in the sheet to be controlled by the toggle selector we set up, you must add a filter to the Filters Shelf with the formula “[The dimension you are using]=[The toggle choice parameter]”. This will filter the result to one thing at a time: the current value of the Toggle Choice parameter.

Add the Toggle Filter to the Filters and select True

Place all three toggle control sheets on a dashboard. Add a horizontal container to the dashboard and place the three toggle control sheets into the horizontal container. To make sure they’re evenly spaced, right-click the dropdown arrow on the container and select Distribute contents evenly.

adding control sheets horizontal container and line graph to a tableau dashboard

Lastly, set up a parameter action for each control sheet that passes the value of the dimension member to the Toggle Choice parameter.

parameter action for each control sheet in Tableau

How to Use Tableau Parameter Dashboard Actions

Each parameter action overwrites the current value of the Toggle Choice parameter integrated within each toggle calculated field in each control sheet and the filter calculated field that controls the line graph. Clicking on a control sheet will change the value of the Toggle Choice parameter, changing both the control sheet image to reflect the selected/true state and the line graph.

Toggling to office supplies on dashboard

This is an awesome user experience, but there are two small things bugging me. By default, Tableau is highlighting the selected image. This defeats the purpose of making my custom images because they are faded until the user deselects the toggle. Also, there’s a black border around the current selection which I’ve never been a fan of. Both of these styles can be removed on each control sheet by adding a Filter dashboard action with each corresponding control sheet as the target.

Dont select Tableau filter dashboard action

Here’s how the final view looks after selecting Supplies.

Final Sales by Supplies Tableau Toggle

 

How to make “America’s okay-ist toggle”

If creating the custom images isn’t for you, I have an easier approach that will provide most of the value of the first approach in much less time.

Learn to navigate uncharted waters.

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

Instead of using a mark type of Shape on your control sheet, use a mark type of Square. Instead of displaying the toggle choice names on images, you can add the dimension containing your toggle choices to the Label Marks Card.

Change the Mark type to Square

Next, place the calculated field being used to filter the individual sheets onto the Color Marks Card of your control sheet. Remember, the formula for this calculated field is “[The dimension you are using]=[The toggle choice parameter]”. In my case, that’s [Category] = [Toggle Choice]. Since only one category matches the current value of the parameter, we get one color for the current selection and a second color for the two unselected options. Of course, you can remap the colors to your liking.

Add the Toggle Filter to the Color property

Everything else works the same way as the first approach. The parameter action controls the current value of the Toggle Choice parameter, which both colors the toggle and filters the line graph. Here’s the dashboard after selecting Furniture again.

Create a parameter action to control the button selection

No custom rounded images and fonts in this version, but an easy way to provide a nice user experience.

Thanks for reading,
– Ryan

Become a member

Get access to this related video & more!

Become a Member

Related Content

Ryan Sleeper

Dynamically change images in a navigation to highlight choices Ryan shares an innovative technique for highlighting dashboard selections in Tableau.…

Ryan Sleeper

Toggle On the Fun with 3 Techniques and 3 Practical Applications In this exclusive Playfair+ webinar, Ryan shares techniques for…