top of page
  • jaredflores0523

Sunburst Chart - Tableau Prep Template

Updated: Jul 11, 2023

All credit for the original template, workbook and method goes to the Flerlage Twins. Thanks for letting me create this!

Sunburst charts can be used to visualize hierarchal data showing how each piece within each segment contributes to the whole. While there are more effective ways to visualize this, the Sunburst chart could fit your use case or it could just be fun to create. Along with the other charts in this series, these are not readily available in Tableau and it takes some data restructuring in order for everything to come together properly.

If you've been following this series, you know the purpose for these Tableau Prep templates. If you are new, click here for a high-level summary

There are plenty of workbook templates with pre-built calculations for visualizations that aren't out-of-the-box in Tableau. Most of those templates require the data to be structured or pre-aggregated a very specific way. This template, as well as the other Prep templates, are to help you take your real-world data, plug it in, and get it in the correct structure to easily plug in to some workbook templates.

The Tableau Desktop template for this chart was created by Ken Flerlage and if you'd like to get more history around the chart and calculations, check out the original blog post: A Template for Creating Sunbursts in Tableau - The Flerlage Twins: Analytics, Data Visualization, and Tableau

As is the case with other workbook templates, there are some assumptions made about the structure of the data. The goal of using this Prep template is to help you get your data in the ideal structure. It requires a bit more work on your end than usual to decide the hierarchal structure of your values, but as we go through and create more Prep templates, the hope is that you become more comfortable preparing your data as well.

You can find the Prep flow and a copy of the Widths sheet here: Sunburst Chart Template - Google Drive

The Data

In the original post, the data is structured like this:

The level represents the placement in the hierarchy. 1 Would be the innermost circle and 3 would be the outermost. The component is the segment of the sunburst, and the parent shows which component each of the lower levels belongs to. The Sort field is used to ensure each of the segments appear in the proper placement on the visualization.

There is also a sheet called 'Widths' that looks like this:

I usually try to build these into the Prep flow so that there are less inputs, but these fields allow you to customize the thickness of each layer of the circle and it's easier to do that by keeping this as a separate input.

Prep Flow

This is what the pre-built portion of the Prep flow looks like.

First you will connect to your data source and drag your table to each of the Level 1, Level 2, and Level 3 steps.

In the Level 1 step, you will pick the top level of your hierarchy. Using the Sample Superstore dataset, we're going to have a sunburst chart that shows total sales by region, and then breaks down category and sub-category sales within those regions. Region would be Level 1 in the hierarchy so we rename the field to 'Component'. Since the chart is breaking the dimensions up by sales, we rename sales to 'Value' and then remove all other fields to only Component and Value remain. Finally, a field called 'Level' is created with a value of 1, which will repeat across all rows.

The aggregate level 1 step aggregates the Value grouped by Level and Component since we need to work with an aggregated version of our data. Since you're likely working with different data, there may be some errors that happen initially but as long as your step ends up looking similar to below you'll be fine:

The Rank step creates a rank for each of the values in descending order. In order for us to create the 'Sort' field that's needed at the end, we're going to use this to ensure everything keeps the proper order.

The Level 2 step and branch is similar to level 1, but we are starting to build the structure. The field that we renamed to 'Component' in level 1 becomes 'Parent' in this step. Whichever field is going to be used as the second level of the hierarchy becomes 'Component'. We still create a field called 'Level' with a value of 2, and Sales is renamed to 'Value'

Again, there may be some errors along the way due to different source columns but you should be able to get things corrected fairly easily. The aggregate step in this branch summarizes the value grouped by Level, Parent, and Component.

The Rank step here starts to become a little more complex in order to keep everything in the proper sort order. First, we create an LOD that gets the total value for each Parent category.

{FIXED [Parent]: SUM([Value])}

Once we have that value, then we create a rank based on the Parent Value using Rank_Dense

{ORDERBY [Parent Value]: RANK_DENSE() }

We remove the Parent Value field, and create a rank that considers the Parent Rank as well

{ORDERBY [Parent Rank] ASC, [Value]: RANK()}

The reason for this is to keep everything moving clockwise in descending order. In our case, the West region has the highest sales, so it will appear first in our sunburst. Then, within the West region, Furniture has the highest sales, followed by Technology then Office Supplies. The Rank created here allows these fields to appear in a descending order in each region.

The Level 3 Step is similar to the previous with the added 'First Parent' column. The field that was 'Parent' in Level 2 becomes 'First Parent', the field that was 'Component' becomes 'Parent', and the field that represents the 3rd level of your hierarchy should be named 'Component'. Sales gets renamed to Value, a field called 'Level' gets created with a value of 3, and all other fields besides these 5 are removed.

The aggregate step here summarizes the Value grouped by Level, First Parent, Parent, and Component.

In the Lowest Level step, the Value field gets duplicated and the duplicate field is renamed 'Lowest Level Value'. The ranking process happens similar to level 2, but we need to repeat it for Parent and First Parent. The final Rank field uses both First Parent Rank and Parent Rank:

{ORDERBY [First Parent Rank] ASC, [Parent Rank] ASC, [Value]: RANK_DENSE() }

In the Sort and Join step, you'll want to remove the First Parent Rank, Parent Rank, Rank, and First Parent fields.

Be sure to download the Widths sheet as well and edit the connection to your file path

NOTE: At this point, the remainder of the flow should come together. If there are any errors, it's likely due to the downstream changes referencing different column names because of a different data source.

Connecting to the Data

Open the template provided by Ken: Sunburst Template | Tableau Public

Go to the Chart sheet and add the output from the prep flow as a new datasource.

Before we replace the original data source, move the Level field from Measures to Dimensions and change the data type of the Value field from decimal number to whole number.

Now replace the data source

All of the calculations will transfer over and you'll have a sunburst chart, although the colors probably look crazy like mine

In the Prep flow, the component field is concatenated with the Parent and First Parent names to make it easier to select colors in this step. To ensure the colors go from dark on the inside and bright on the outside, I first edited the sort on Component to be in descending order

Double click the color legend and assign every component colors to your liking. I did this by holding CTRL and selecting every value within a segment, for example West and all of the components ending in '-West' and assigning a gradient color palette.

Once you've selected your colors, change the sort on Component back to Ascending and you'll be done!

I hope you are able to make use of this Prep template! If you'd like to learn how it was built, check out the video here: Sunburst Chart Tableau Prep Template: Put Some Prep In Your Step - YouTube

467 views0 comments


bottom of page