by Brian Moore
Of all of the things I love about Tableau, its incredible flexibility is by far number one on my list. With a little bit of creativity, a healthy dose of tenacity, and occasionally a little help from the #datafam, you can make anything happen in Tableau. The possibilities are literally endless. So recently, when I ran into some default functionality that I wasn’t entirely happy with, I set off to figure out a way around it. This post is about getting better control over the default highlight functionality when selecting marks in your view.
Here is a quick example of what we’re talking about. When you click on a mark in your view, by default, the selected mark maintains its color, and the remaining marks turn a very light, washed out version of that color. It’s great that Tableau built in functionality that allows users to quickly identify which mark or marks are selected, but in an ideal scenario you would be able to control how those marks look.
When you have a light background, the remaining marks are barely visible. When you have a dark background, the remaining marks are bright and distracting from the selected mark. The first step in controlling how these marks appear is to prevent the default highlight functionality.
Preventing Highlight Functionality
Step 1: Create calculated field called “Highlight” with “” in the body of the calculation
Step 2: Drag the “Highlight” field on to the Detail Shelf in your worksheet
Step 3: Create a Dashboard Highlight Action. Select the sheet(s) where you want to prevent highlighting in both the Source Sheets and Target Sheets. Under Target Highlighting, choose “Selected Fields”, and select only the “Highlight” field
The default highlighting is disabled by basically forcing Tableau to highlight all of the marks in the view instead of just the selected one. However, now you are not able to see which mark or marks are selected. So the next step is to use dashboard actions and color to control how the selected and remaining marks will appear. This can be done with a set or parameter action, but we’ll start with a set action.
Color Marks Using Set Action
Step 1: Create a set by right clicking on any mark in your view, selecting “Create Set”, and then removing any fields other than the one in your view
Step 2: Drag your new set to the Color shelf
Step 3: Adjust your colors. Set the “In” value to your base color, in this case blue, and set the “Out” value to whatever color you want for your remaining marks
Step 4: Create a Dashboard Set Action. Under Source Sheets, select the sheets where you want to control the highlighting. Under Target Set select the data source and the set created in the previous steps
If you are only interested in selecting one mark at a time, a similar effect can be gained using parameter actions.
Color Marks Using Parameter Action
Step 1: Create a Parameter. Change the Data type to “String” and set the Current value to “All”
Step 2: Create a Calculated Field called “Bar Color”
IF [Field]=[Parameter] or [Parameter]=”All” then “Base Color” else “Other” END
Step 3: Add the “Bar Color” field to the Color Shelf
Step 4: Create a Dashboard Parameter Action. Under Source Sheets, select the sheets where you want to control the highlighting. Under Target Parameter select the parameter created in the previous steps. Under Field select the field in your view, and set the Aggregation to None
Step 5: Adjust your colors. Set the “Base Color” value to your base color, in this case blue, and set the “Other” value to whatever color you want for the remaining marks
This allows you to control the color of the selected and remaining marks, but it does not let you remove a selection, like it would with the default functionality, or with a set action. If you want to be able to remove a selection so that all marks are highlighted, you can use another calculation.
Color Marks Using Parameter Action – Part 2
Step 1: Create a calculated field called “Remove Selection
IF [Field]=[Parameter] then “All” else [Field] END
Step 2: Add this field to the Detail Shelf in your views
Step 3: Edit your Parameter Action. Under Field, select the “Remove Selection” field
These methods work great for controlling the highlighting functionality when only a single color is used in the view, but what if you wanted to have multiple colors in your view, and still maintain the color of the selected one? This can be accomplished with just a quick change to the Bar Color calculation.
Step 1: Update the “Bar Color” field. In the body of the calculation, set it equal to whatever Dimension you want to color your data by. In this example we’ll use Region
Step 2: Update your colors however you like
Step 3: Update the “Bar Color” calculation again
IF [Parameter]=”All” then [Color by Field] ELSEIF [Parameter]=[Field] then [Color by Field] ELSE “Other” END
So that’s it. With just a few quick calculations and some simple dashboard actions you can override Tableau’s default highlight functionality, and gain more control over how your dashboards appear to your users.
This is Sons of Hierarchies first guest blog, courtesy of Brian Moore. Brian is a Senior Analyst at Bentley University, Data Enthusiast, Proud Dada, and One-Time Perfect Game Bowler. You can find on Twitter and Tableau Public.