Tableau tooltip tip week - Bar charts in tooltips

by Ben Moss

YOU CAN DO BAR CHARTS IN YOUR TOOLTIPS…WTF.

How awesome does that sound?

Why is it awesome? It is an opportunity to provide your users with additional information, without taking up any space.

When they are used well they can be extremely effective in adding detail to the story you are trying to tell.

Picture 1 - Tableau tooltip tip week - Bar charts in tooltips

One thing to note is that there is already a great Tableau knowledge base article on this subject which is where I learnt from…I’m going to pretend this doesn’t exist.

So how do you make bar chart in tooltips?

(note there is a ‘how to video’ at the bottom of this article which may better suite your learning style)

Well to start off lets pretend we have two columns, one a dimension, lets say [Segment]. Within this dimension we have three dimension members, ‘Consumer’, ‘Corporate’ and ‘Home Office’.

We also have a measure, lets say [Sales].

Of course, in order to create a bar chart in Tableau we need at least one dimension and one measure (Which we have).

Now, for the trick…for each dimension member in your segment you will need to create two calculated fields to create our bar chart in the tooltip. #

So clearly do not do this if there are, I would say, more than 10 dimension members, it will just get extremely messy. But that’s just my thoughts, and in theory it should work no matter how many dimension values you have.

So in our example we have three dimension members, so we will have to create 6 calculated fields.
________________________________________________
The first formula we will create for, for each dimension member is as follows (in the video I have called these by simply the dimension member name).

IF [Dimension]=”dimension member” THEN [Measure] END

So in our case

‘Consumer’ – IF [Segment] = ‘Consumer’ THEN [Sales] END

‘Corperate’ – IF [Segment] = ‘Corperate’ THEN [Sales] END

‘Home office’ – IF [Segment] = ‘Home office’ THEN [Sales] END

So this formula will create a new column for each dimension member which only shows the Sales value when that dimension member equals the segment.
________________________________________________
The second formula we will create will use the above information to actually create our bars.

LEFT (“■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■”, ROUND(SUM([Dimension Member])/SUM([Measure])*100,0))

So in our case

‘Consumer bar length’ – LEFT (“■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■”, ROUND(SUM([Consumer])/SUM([Sales])*100,0))

‘Corperate bar length’ – LEFT (“■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■”, ROUND(SUM([Corperate])/SUM([Sales])*100,0))

‘Home office bar length’ – LEFT (“■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■”, ROUND(SUM([Home office])/SUM([Sales])*100,0))

 

What does this do?

I’m just going to break the formula down into two parts, firstly this part… ROUND(SUM([Dimension Member])/SUM([Measure])*100,0))

so…SUM([Dimension Member])… represents the sum of the measure for that dimension member

……SUM([Measure])… represents the sum of the measure

so… (SUM([Dimension Member])/SUM([Measure])*100)… gives the % value that the dimension member contributes to the total.

wrapping the ROUND() function around this formula will of course round (obviously) our formula to the nearest integer.

 

Now bringing in the second part

LEFT (“■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■”, ROUND(SUM([Dimension Member])/SUM([Measure])*100,0))

So lets understand what the LEFT function does in tableau.

It returns the specified number of characters from the start of a string.

LEFT(“STRING”,NUMBER OF CHARACTERS”)

so…

LEFT (“■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■”, ROUND(SUM([Dimension Member])/SUM([Measure])*100,0))

Will return however many squares are represented by our [Dimension Member] (in terms of % of total) from the start of the string.

In our “■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■” string there are 100 ■’s

ARRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR (I hope this is the moment you understand this!).

So doing this for each of our dimension members will create our bars for them.

Thus all we now have to do is drag them onto the tooltip and we have our bar chart!
________________________________________________

A few of quick tips to finish off…

  1. We can alter the unit value for each bar in terms of % total by making a slight alteration to our second formula…LEFT (“■■■■■■■■■■”, ROUND(SUM([Dimension Member])/SUM([Measure])*10,0))

    So each bar now represents 10% rather than 1%. It will reduce the size of your tooltip and help make it a bit cleaner.

  2. You can replace the ■ with any characters, pi if you so wish π 
  3. By dragging the actual value that these bars represent will help give your users further detail. Simply drag each of the first formulas for each dimension member onto the tooltip and format your tooltip accordingly.

Thanks for reading my blog! I appreciate that this tip may seem complex, but I hope my blog reads in a way that makes it easy to understand! If not, the how to video below may be of interest.

Ben

 

 

 

 

 

 

 

Thu 25 Feb 2016

Wed 24 Feb 2016