Tableau Bar Charts in Tooltips

Displaying distribution or composition can be difficult on certain views such as maps or scatter plots, when the axis is dedicated to latitude and longitude or other measures. Using pie marks is an option, but often users have trouble discerning the size differences among slices in this mark type. This article covers a method to incorporate distribution or composition information as a bar chart within tooltips.

Cohort calculations

Using the method described in this article, creating a cohort calculation involves using one measure and one dimension.

Step 1

Create a calculated field that separates the measure so that it is specific to each member of the dimension. The calculated field should have a formula that fits using the following syntax:
IF [Dimension]="member 1" Then [Measure] END 

Step 2

Repeat step 1 for each member in [Dimension]. You should have a separate cohort calculated field that describes the [Measure] for each member.
BarChartTooltips2.png

Creating calculated bar field

The purpose of using bars within a tooltip is to have a calculated string field that represents the appropriate length of each bar. Then, you can apply suggestions in the"Customize Tooltips" section of the Conditionally Formatting Tooltips article.

Step 1

Right-click anywhere inthe Data window, and select Create Calculated Field. This calculation represents the bar length for one of the dimension members.

Step 2

In the Formula textbox, determine which of the following designs you wish to use, and then use one of the following formulas:
  • If you want hashed bars, use:
LEFT("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",ROUND((SUM([Your cohort calculation])/SUM([Measure]))*100,0))

For example:

LEFT("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||",ROUND((SUM([Coffee Sales])/SUM([Sales]))*100,0))
 
Formula for hashed bars

  • If you want solid bars, use"█". This character is ASCII character 166, in the Arial Unicode MS font.
LEFT("█████████████████████████████████████████████████████████████████",ROUND((SUM([Your cohort calculation])/SUM([Measure]))*100,0))

For example:

LEFT("█████████████████████████████████████████████████████████████████",ROUND((SUM([Coffee Sales])/SUM([Sales]))*100,0))


The bar length in the tooltip is determined by the calculation:
ROUND((SUM([Cohort Calc 1])/SUM([Measure]))*100,0)
This formula determines the percentage of total of that member. The first part of the calculation (“||||" or "█") is the characters that makes up the bar length. Because the percentage of total calculation is a rounding out of 100, place 100 "|" or "█" in the calculation to represent the accurate values.

Step 3

Repeat steps 1-2 for each cohort calculation you creating in the first section.

Step 4 (optional)

Apply the new calculated string fields to the level of detail and follow the steps outlined in the"Customize Tooltips" section of the Conditionally Formatting Tooltips article for tips on how to format and arrange tooltip content.
Thanks to Andy Cotgreave, who blogs at www.thedatastudio.co.uk, for submitting this idea.