Fisseha Berhane, PhD

Data Scientist

CV Resume Linkedin GitHub twitter twitter

Multi-column Sankey Diagram with Filters in Tableau

The Tableau Dashboard is at the bottom of the page

Sankey Animation

Sankey diagrams are a kind of flow diagrams in which the width of the arrows is shown proportionally to the flow quantity. Creating most visualizations in Tableau is intuitive but creating a sankey diagram is not. One of the capabilities of Qlik sense that I like is its plug-ins for D3 libraries which enable seamless integration of sankey diagrams, network graphs, etc. in our dashboard. Even if creating sankey diagrams in Tableau involves some effort, sometimes, it is worth it because it is visually attractive and it can help to show flow of data which cannot be represented using other data visualization types.

In this post, we will create sankey diagrams using Tableau. There are already some tutorials out there that show how to create sankey. However, what makes this tutorial different is that it shows how to use filters in the sankey diagrams. Further, this blog post is on multi-layer sankey. The data is from Tableau’s website. You can download it from here. You can also download the Tableau dashboard. I have also included screenshots of the calculated fields.

The steps are below. We have to repeat all the steps for each part of the Sankey diagram (one for the Sankey from Product Category to Region, one for the Sankey that goes from Region to Ship Mode and one for the Sankey that goes from Ship Mode to Order Priority)

We can use one or more parameters to filter our data. In this dashboard, we are using year parameter to choose year.

  • When connecting Tableau to the data source, open it using 'legacy connection'
  • Click on 'Data' on the upper left and select 'Convert to Custom SQL'. This should be done after dragging the sheet you want to the canvas on the right.
  • Copy the custom SQL and using 'UNION ALL', paste it below the original one
  • Add a new column (call it vizside) with names for the left and right sides of the Sankey diagram

  • Create a parameter to help us select year

  • Create calculated fields for vizside and for the field you want to use for sizing (sales in our case)
  • Create a calculated field called "ToPad"
  • Create bins from "ToPad" using a bin size of one, call it "Padded"
  • Create a calculated field called "t"
  • Create calculated fields called Rank 1 and Rank 2. Rank 2 is a copy of Rank 1
  • Create a calculated field called "Sigmoid"
  • Create a calculated field called "Curve"
  • Drop "t" the column shelf and "Curve" to the rows shelf
  • Drop "Padded", "Product Catgory" and "Region" to the details shelf
  • Rank 1 and Rank 2 should be computed as specified below and 't' should be computed usig "padded"
  • Drop "Padded" to Path and change mark type to line
  • Create a calculated field of the measure you want to use to show the size of the flows. Drop that to the size marks and it should be computed using "Padded"
  • Remove headers from the axis, make x-axis from -5 to 5 and y-axis from 0 to 1 and reverse the y -axis
  • Create bar graphs for both sides of the sankey in separate sheets
  • Next, create the other sankeys (one for the sankey that goes from Region to Ship Mode and one for the sankey that goes from Ship Mode to Order Priority). Here, you just need to duplicate the first sankey and change Product Category and Region by the appropriate columns and then Edit Table Calculation for 'curve'.
  • Create a dashboard using the sankey diagrams and the bar graphs
  • Create dashboard actions, for each sankey, that highlight on hover.
comments powered by Disqus