Tableau – Expand and Collapse Hierarchy using Parameter

by Sreekanth Arathil Condoth

In Tableau one can create a hierarchy using multiple dimensions, which enables an easier drill down on the views. The drill-down is done by clicking the + or – symbol on respective views. This way of expanding and collapsing the hierarchies can be cumbersome when it needs to be performed on multiple views. This is a typical scenario where using parameters can be helpful. With the help of a parameter, the expansion and collapsing of the hierarchy on all the views can be done at the same time with just one click. In this blog, I will explain this method.

In the Sample Superstore dataset, there are some built-in hierarchies. One of them is the Product hierarchy, as shown below.

Using the Product hierarchy, I have created two charts and one table which were then added to a dashboard as shown below.

Now a parameter is created which will enable us to expand and collapse the hierarchy in all the views at the same time. In this example, I want to drill down to one level, that is the Sub-Category level and then collapse back to the main level which is the Category level. So in the parameter, we need to provide the respective levels to expand and collapse.

The next step is to create two calculated fields, one each for Category and Sub-Category. The top-level, that is Category need to be always displayed on the views. To do that, we simply drag the dimension Category into the calculated field for Category. In the lower levels, in our example the Sub-Category will only be displayed when the corresponding value is selected on the parameter. This can be achieved using the IF-Condition as shown below. The ELSE clause is added to avoid displaying of “NULL” when Sub-Category is not selected in the parameter.

The last step is to replace the Category and Sub-Category on all the views with the newly created calculated fields.

Now one can use the parameter to drill down the hierarchy on all the views at the same time.