When creating labeledvisualizations in Tableau, I have often wanted to provide clients the ability to toggle between the measure that is labeled. The toggle is fairly simple with parameters, but what happens when one of the measures is a percentage, one is currency, and the third measure is a whole number?
This is where dynamic formatting with a few calculations comes into play. Wow your end users and give them the utmost flexibility!
We will be using data from Sample Superstore for this example.
First we will define the three labels we desire:
- Monthly Sales ($)
- Month over Month % Difference in Sales (%)
- Monthly Order Volume (#)
Let’s start with the parameter which we will call “Label”
Next, let’s make sure we have the correct measures that we want to label.
- Sales (that’s an easy one) – default property set to currency
- Month over Month % Difference
- I do this by throwing the MONTH date dimension on the columns shelf, sales on rows
- Convert sales to a quick table calculation, “Percent Difference”
- Make sure it’s computed along “table across” using the previous value
- Double click on the new sales quick table calculation pill on the rows shelf and copy the formula inside.
- Create a calculated field and paste the formula
- Set the default property to a percentage
- Order Volume
- Create a calculated field and do COUNTD ([Order ID])
- This will become a measure
This is where the parameter and the calculation will come together to drive what happens on the visual. I will create three additional calculations using CASE logic to sync the calcs with our label parameter. You will notice that the other 2 options are “nulled.” I have don’t this intentionally.
- Sales Selected
- Month over Month Difference Selected
- Order Volume Selected
Place all three calculations onto the marks label.
Because the parameter is in play only the calculation that is associated with the parameter selected will show up. The other calculations are null and therefore do not show in the view. Voila!
Enjoy using the toggle feature!
By: Barclay Klingel
Posted by admin