Using hierarchies is another way of slicing and dicing our data. This gives us the ability to be able to drill up and drill down into the data at various granularities. We have already seen an example of a default hierarchy in Tableau when we use any Date field.
When we get any Date field in either the Rows or Columns shelf, Tableau automatically aggregates it to the highest possible level. For example, if the date field includes multiple years, the default level is year. But, if the date field contains data for just one year but includes multiple months, then the default level is month.
In our data, if we get the Order Date field in the Rows shelf, then Tableau aggregates it at the Year level and gives us a field called YEAR(Order Date). It also gives us the + button (expand button) so that we can easily break down the view by year, quarter, month, and so on. Refer to the following image:
When Tableau identifies a field as a Date or Date/Time field, it creates the Date hierarchy by default. There could, however, be instances when we would want to create some custom hierarchies in Tableau. Let's say we have region, country, state, city, and so on. and we want to create a hierarchy with these fields to quickly drill through each level. In the following recipe, let's look at the steps to create a custom hierarchy in Tableau.
We will continue with the above stated example and create a custom hierarchy. We will use the fields State, City, and Postal Code from our already connected Orders data of the Sample - Superstore.xlsx
dataset. We will continue working in our existing workbook. Let us go through the recipe to create a custom hierarchy.
Custom Hierarchy
.When we click on the + (expand) button on the Blue pill for State in the Rows shelf, we will drill down to the City. Now the Blue pill for State gets a - (collapse) button and the Blue pill for City gets a + button. This will happen for each drill-down level. One very important point to remember when creating hierarchies is to select the Dimensions in the order of how we want the hierarchy to drill down.
Another way to create hierarchies is by selecting multiple dimensions (Ctrl + Select) in the Data window, right-clicking and selecting the Hierarchy | Create Hierarchy…option. However, one may need to rearrange the Dimensions in the hierarchy when using this option. Refer to the following image:
3.149.249.252