What is a hierarchy in Tableau?
Hierarchy in Tableau refers to the logical structure of displaying fields or levels to enable users to break down data in a view. When you create a hierarchy in Tableau, you create a level of data similar to a tree-like or hierarchical structure, which can be quickly drilled down to get data insight. For example, you can create a Product hierarchy containing different levels of granularity such as Product Segment – Product Category – Product Sub-Category – Product Name. By default, Tableau creates certain hierarchies, such as date hierarchy in Tableau and demographics, when you source the dataset into it. However, you can create custom hierarchies using fields in your dataset in Tableau as well.
A sample Tableau hierarchy looks like the one highlighted below. As you can see, the Tableau view displays data fields at different levels of the hierarchy. A sample Tableau hierarchy looks like the one highlighted below. As you can see, there are data fields at different levels of the hierarchy displayed in the Tableau view.
Key Takeaways
- Hierarchy in Tableau is a logical representation of levels that looks like a hierarchy or tree-like structure. It allows users to quickly drill down into the fields in the Tableau view.
- Tableau creates auto-hierarchies for specific data types, such as demographic fields or date hierarchy in Tableau. However, you can create custom hierarchies using fields in your dataset in Tableau.
- You can create hierarchies in Tableau by using the Create Hierarchy option or dragging and dropping a field on another in the Tableau view.
- You can amend existing hierarchies, rearrange the fields within hierarchies, or remove existing hierarchies in Tableau. You can create hierarchies spanning across multiple dimensions in Tableau.
- Hierarchies, once created, can be shared and reused across the Tableau workbooks.
How to Create a Hierarchy in Tableau?
To create a hierarchy in Tableau, follow the below steps.
Step 1: Import your data source into Tableau public.
Step 2: Navigate to a new worksheet. In the Data pane, drag a field and drop it directly on top of another field. In this case, we have dragged the Product Name and dropped it on the Product ID. As you can see, Tableau has popped up a Create Hierarchy screen.
Step 3: Enter a meaningful name for the hierarchy and then click on OK to save the changes. You will notice that Tableau has automatically added a hierarchy Product with the dragged fields underneath.
Step 4: You can drag additional fields into the newly created hierarchy as required. Tableau allows you to re-order the fields in the hierarchy by dragging them into a new position.
Here, we have dragged and dropped additional fields such as Category, Sub Category, and Segment fields into the Product hierarchy and rearranged the fields under the Product hierarchy.
Step 5: Drag the newly created hierarchy to the Rows shelf and a measure to the Columns shelf to create a data visualization. Once you have created it in the Tableau view, it will look like the one below.
Tableau shows differences between groups and hierarchies. Refer to the Tableau documentation for more information.
In the next section, we will examine different examples of how to create hierarchies for your data visualization requirements.
Examples
In this section, we have outlined a few examples that will enable you to create hierarchies in Tableau in your workbook.
Example #1 – Create multiple hierarchies
In this example, we have demonstrated creating multiple hierarchies in Tableau using the UEFA EURO 2024 – Players dataset, which contains details about clubs, age, height, market value, etc., of all the players that are in the squad of the teams participating in the UEFA EURO 2024.
To create multiple hierarchies, look at the steps below.
Step 1: Begin by importing your dataset into the Tableau interface using the File Navigator.
Step 2: Navigate to a new worksheet. In the Data pane, right-click on the dimension/field on which you want to create a hierarchy. Choose Hierarchy – Create Hierarchy option on the context menu.
Step 3: Provide a meaningful name to the Hierarchy in the Create Hierarchy dialog box.
Tableau will automatically create the hierarchy visible in the Data pane.
Step 4: Drag and drop additional fields to the hierarchy. Here, we have added Position and Foot dimensions to the Player hierarchy.
Step 5: Drag the Country field and drop it over the Club field. Tableau will pop up a Create Hierarchy dialog box. Provide a meaningful name to the hierarchy and click on OK.
Tableau will create a hierarchy of Player Demographics visible in the Data pane.
Step 6: Drag the Player hierarchy to the Rows shelf and Market Value to the Columns shelf. Tableau will create a bar chart in the view as shown below.
Example #2 – Drill Up
In this example, we demonstrated how to apply drill-up in hierarchy using the Airlines dataset in Tableau.
You may follow the instructions outlined below to apply to drill up in hierarchies in Tableau:
Step 1: Import the Airlines dataset into Tableau public using File – Open in Tableau interface.
Step 2: Create a hierarchy in the Data pane. Here, we have created a hierarchy of Aircraft containing the Aircraft details such as Aircraft Body Type, Aircraft Manufacturer, and Aircraft Model dimensions.
Once you click on OK, Tableau will create a hierarchy in the Data pane, as shown below.
Step 3: Repeat a similar process to create another hierarchy of Operating Airline Details.
This hierarchy is created by including Operating Airline and Operating Airline IATA Code dimensions.
Step 4: Similarly, we have created another hierarchy of Published Airline Details encompassing Published Airline and Published Airline IATA Code fields.
Step 5: Repeat the process to create a GEO hierarchy. It must contain GEO Region and GEO Summary fields.
Step 6: Drag the Aircraft hierarchy to the Rows shelf and GEO to the Columns shelf. Tableau will add a visualization to the view, as shown below.
Step 7: Click on the Color – Edit Colors. Select a color palette from the drop-down menu.
Tableau will color-code the view as provided below.
Step 8: Expand the Tableau view by clicking on the + icon against the hierarchy field in the Rows shelf. You can see that post-expansion, the Aircraft Manufacturer field is now included in the Tableau view.
Step 9: Expand the Tableau view further by clicking on the + symbol next to the Aircraft Manufacturer field. Tableau will now display the Aircraft Model field in the view.
It can be further expanded to include Landing Aircraft Type in the view.
Step 10: Now, hover your mouse/cursor over the Aircraft Model, and you will notice the – symbol. Click on that symbol. You will notice that Tableau has applied drill-up to the hierarchy.
Step 11: Again click on the – symbol on Aircraft Manufacturer to further drill up in the Tableau view.
If you continue applying the drill up in the hierarchy, you will notice the below Tableau view.
Example #3 – Drill Down
In this example, we will show you how to drill down in a hierarchy in Tableau using the Data Developer Salary in 2024 dataset. This dataset contains details on data developer salaries and employment attributes such as employment type, salary, employee residence, remote work ratio, company location, and company size.
To drill down into a hierarchy in Tableau, let us consider the steps outlined below.
Step 1: Open Tableau public/Desktop on your machine and connect to your dataset from the Tableau interface.
Step 2: Create a hierarchy by right-clicking on a dimension. Then, choose Hierarchy – Create Hierarchy option.
Step 3: Provide a meaningful name to the hierarchy. Tableau will create a hierarchy in the Data pane, as shown below. Here, we have created a hierarchy called Company.
Step 4: Drag and drop the Company Size field to the Company hierarchy.
Step 5: Similarly, create another hierarchy of Employment. For this, drag and drop the Employment Type on the Employee Residence.
Step 6: Add additional dimensions such as Experience Level and Job Title to the hierarchy.
Step 7: Drag the Employment hierarchy to the Rows shelf and Salary in USD to the Columns shelf in the Tableau view. Tableau will create a visualization, as shown below.
Step 8: Drag the Salary in USD to the Color and then Click on Color – Edit Colors on the Marks card. In the Edit Colors screen, choose a color palette. Here, we have selected the Red-Green Diverging option. Click on OK to apply changes.
Step 9: Now, click the + icon against Employee Residence on the Rows shelf.
Step 10: Tableau will expand the Employee hierarchy in the Rows shelf, and you will see Employment Type in the Tableau view. In other words, Tableau will Drill Down the hierarchy, reflecting the salary values as per the hierarchy.
Step 11: Again, Drill down further by clicking on the + symbol against the Employment Type. This will expand the hierarchy in the Rows shelf, and now the Experience Level is visible in the view. The salary values are reflected as per the chosen drill-down level.
Step 12: Expand the hierarchy further by clicking on the + sign next to Experience Level. Tableau will add the Job Title to the view and the salary in USD value as per the hierarchy as shown below.
How to Remove Hierarchy in Tableau?
The instructions outlined below show how to remove hierarchy in Tableau.
Step 1: Open your Tableau data visualization containing the hierarchy in your dataset.
Step 2: In the Data pane, right-click on the created hierarchy and then select the Remove Hierarchy option from the context menu.
You can now see that the fields in the hierarchy have been removed from the hierarchy, and the hierarchy is no longer visible in the Data pane.
Important Things to Note
- Hierarchy in Tableau works only for dimensions, not for measures. You can’t create a hierarchy using measures in Tableau.
- You can rearrange the positions of the dimensions in a hierarchy and create multiple hierarchies in a dataset.
- You can apply filters on the fields included in a hierarchy.
Frequently Asked Questions (FAQs)
Yes, hierarchies can certainly span multiple dimensions in Tableau. By choosing the relevant fields into the hierarchies, you can create a hierarchy of demographic dimensions (City, Location, Country, etc.), date dimensions (Year, Month, Quarter, Week, etc.), or custom dimensions such as Customer, Employee, and Product, etc.
Hierarchies can be both static and dynamic in Tableau. Static hierarchies require manual intervention to alter or amend any changes. For example, adding new dimensions, removing existing dimensions, changing the order of fields within a hierarchy, or changing the hierarchy’s name in Tableau requires manual intervention.
Similarly, you can use parameters and calculated fields within a hierarchy to create a dynamic hierarchy in Tableau. The dynamic hierarchy in Tableau can change with user interaction or any changes to the underlying dataset.
No, you can’t use hierarchies in calculations or formulas in Tableau. However, you can use the individual fields within a hierarchy to create calculated fields and use them in formulas.
Yes, hierarchies can be shared and reused in Tableau workbooks. Once a hierarchy is created in a worksheet, it is available for use in other Tableau workbooks as well. Similarly, if you remove or amend any existing hierarchy, the same will be reflected across all the workbooks in the Tableau.
Download Template
This article must help understand Hierarchy in Tableau with its formulas and examples. You can download the template here to use it instantly.
Recommended Articles
Guide to What Is Hierarchy in Tableau. Here we learn how to create Hierarchy in Tableau, how to remove them, with examples and points to remember. You can learn more from the following articles.
Leave a Reply