Dynamic Labeling in Axis Hierarchies

Sep 27, 2018

Klaus Schulte

For this week’s #workoutwednesday challenge I recreated a viz by Rody Zakovich (click to play with the interactive version on Tableau Public).


What I like most about these challenges is that I have to stretch myself a lot. Yes, I’m still failing sometimes to implement all these evil tricks by Ann, Rody or Luke, but I really feel that I learn a lot. And there have already been cases, where I could take this new knowledge and create other/own use cases, like for example in last week’s post on synchronized scrolling or in this post on Dynamic Labeling & Axis Hierachies.

So what’s the problem with labels and axis hierarchies?

When you use for example a date on columns, Tableau allows the user of your dashboard to drill this date dimension up and down.

Profit by Month:

blog 1

Profit by Quarter:

blog 2

Now look at the axis label: For the case that you use a custom label (you changed the label of your axis by ‘edit axis’) Tableau isn’t able to change the label based on the selected hierarchy level anymore. It labels the axis “MONTH of Order Date” statically.

There is a way to deal with this problem by using parameters, like described in this blogpost found in the Tableau Community Forum by Rahul Singh.

In this post I want to share a way to label a viz by the chosen hierarchy level dynamically without using a parameter, meaning that it is still possible to use the little “+” and “-” for drilling.

This can be done in the axis label by using the default label, I used the sheet title to create this:


If you want to recreate this, these are the steps:

1. Create a string calculation

Basically it is just one calculated field/string calculation you need. To create this you have to explore your hierarchy first to know about the number of levels in your hierarchy. In my case I had year/quarter/month/week/day. Then I’m counting the number of elements on each hierarchy level by using the ‘datediff’ formula (I could have also used LODs to do the same) to compare the result with size(), that is counting the rows in my partition. I also wanted the hierarchy level to be displayed in capital letters, therefore I used the upper() formula.

blog 3

Make sure that size() is computed in the right direction, in my case across the table.

2. Edit the sheet title

All you have to do then is to insert this calculated field and the measure name (in this case a parameter) in your title!

blog 4

That’s it!


Hope you enjoyed this post and that you will find use cases for this!