Wednesday, May 6, 2020

A Template for 3-Stage Sankey Chart in Tableau

Quite a few people visited my post on creating 3-stage Sankey chart by cascading 2 Sankey charts. It's a scalable approach which can lead to N-stage Sankey chart using the same building block repetitively.

It seems 3-stage Sankey chart is a popular one. I think it's worthwhile to create a monolithic template like the minimal Sankey template. It takes only a few simple steps in a few minutes to quickly create a 3-stage Sankey chart. It will save you a lot of time. I hope this will make everyone a creator of the curvy Sankey chart. I need to acknowledge that this template is inspired by the original contributions of Jeffrey Shaffer, Olivier Catherin and Ken Flerlage.

Three Steps

So here you go a new tutorial on building 3-stage Sankey chart in Tableau. It takes 3 main steps:

- Import your data into the template and union the data set with itself.

- Rename Stage1/2/3 and Size in the template according to the 3 dimensions and 1 measure in your data set.

- Replace template data source by your data set. Resize the dashboard components to make appear the labels, if necessary.

More details please refer to the video tutorial.

Template Screenshot
Sankey chart on Grand Prix below is created using the above template.

Caveat

In the 2020.1 version of Tableau, there is a glitch in replacing data source. We may need an extra step by "Replacing References". See video tutorial for more details.

That's it. Feel free to download the template and create your own Sankey chart. Please leave questions in the comment area if any. Enjoy Sankey!

Sankey Chart Series in Tableau
5.A Template Approach to 3-Stage Sankey Chart
3.Creating Sankey Chart with Grouping
2.Creating Multi-Stage Sankey Chart via Template Cascading
1.Creating Sankey Chart Made Easy via Template

26 comments:

  1. Hi Alex, thanks for creating this template! I followed all the steps and successfully replaced the data source and calculation references, but I'm having trouble with the "Path (bin)" field. I get an error (red !) saying the calculation is invalid. How is this field computed? I thought maybe you binned the "size" measure, but trying that yielded a range of 0 to 22,638 not 0 to 97.

    ReplyDelete
    Replies
    1. It’s binned on the field Path. Did you union the data source first?

      Delete
    2. Oh, that must be the issue - there is no field "Path" in the template you linked (https://public.tableau.com/views/3-StageSankeyTemplateinTableau/3-StageSankeyTemplate?:display_count=y&:origin=viz_share_link&:showVizHome=no). Yes, I unioned the data first (via custom sql - I hope that's ok).

      Delete
    3. When using custom sql, did you create an extra field ‘Table Name’ to denote upper and lower tables differently? Say, table1 and table2. That’s crucial to the data union.

      Delete
    4. I did create a dimension for that purpose, but didn't call it "Table Name" - I'll rename things to match your suggestion. Will that solve the issue of the missing "Path" field though?

      Delete
    5. Yes. It will solve the problem. Don’t worry about Path. It’s hidden.

      Delete
    6. I wrote here about how to union in sql http://vizdiff.blogspot.com/2018/12/creating-sankey-chart-as-easy-as-1-2-3.html

      Delete
    7. That solved the issue! Thanks so much for talking me through this, Alex!!!

      Delete
  2. So glad you made it to work. Your table fields have to match those in the template exactly!

    ReplyDelete
  3. Hi Alex, this template is very easy to use! I'm wondering how do I change the colour of the arms so that (in the example above) - if Furniture is pink, I want all the arms coming out of furniture to be pink and follow through to the end in the same colour. I tried putting Stage 1 in Colour in the Marks card but it broke the chart. Thanks

    ReplyDelete
    Replies
    1. The pink part is going to the East region. From East to the end, we need to use a composite dimension like stage1+stage2+stage3 to highlight or color the the arms.

      Delete
  4. Try this one for any number of stages: https://vizdiff.blogspot.com/2020/01/creating-3-stage-sankey-chart-via.html

    ReplyDelete
  5. Hi, thank you for this template! Is it possible to show size as a % of the source rather than target?

    E.g. 25% of furniture orders come from the central region rather than 30% of central region orders are furniture

    ReplyDelete
    Replies
    1. Just added both sizes per source and per target to the template. Check it out and see if it works for you.

      Delete
  6. Thank you for the excellent template. I was wondering if there is any way to create this Sankey charts with some missing data on the second and third stage. I am trying to plot some kind of divergence pattern from the first stage to second stage, and from second stage to third stage. But some of the groups does not diverge at second or third stage, when i provide the input, i have tried not to fill anything in the second/third stage or putting NA, all does not works well. And finally i have tried to use the exclude function of tableau to remove the accumulated "empty bar", but the intermediate curvy line did not change accordingly. Could you kindly help on this?

    ReplyDelete
    Replies
    1. Could you try this cascading approach? http://vizdiff.blogspot.com/2020/01/creating-3-stage-sankey-chart-via.html

      Delete
    2. Hi Alexander, thank you so much for your response to my inquiry. I have read through your post in http://vizdiff.blogspot.com/2020/01/creating-3-stage-sankey-chart-via.html but not sure how this will help with my problem. I have uploaded the sankey graph I generated and the raw txt file and your template file to the following link: https://www.dropbox.com/sh/ufpsrea2rfucjvz/AACAZPR1yCi5aTEJHxJc2T3Oa?dl=0 . My problem is that some of the items in the first group do not need to have any divergence to the second group, and some of the second group do not need to have any divergence to third group as well. But I am not sure how i can accomplished this, as the current graphs will just group all the empty cells into a independent bar in the graph. I needed this template to work so much, i appreciate for your help. Thank you in advance

      Delete
    3. 1.Yes try grouping as described here https://vizdiff.blogspot.com/2020/01/creating-sankey-chart-with-grouping.html
      2.Try set the color to be white for those branches you want to hide.

      See if this solves your problem.

      Delete
    4. Looked into the files you shared. If you can draw a picture of the expected outcome, it would be greatly helpful. Hand drawing is fine.

      Delete
    5. Hi Alex, so thrilled to have found this template! My version of Tableau is 2020.4.13, so after following all the steps I still have "Bar Position" and "FlowSize" broken (calculation invalid). Any instructions on how to fix it?

      Delete
    6. Could you send me the workbook? alexandermou2000 at gmail

      Delete
  7. Hi.
    First of all, thank you for explaining in detail how to apply a simple raw chart.

    Is there a simple way to change from a 3STAGE template to a 4STAGE template?

    ReplyDelete
    Replies
    1. Please refer to this technique on building 4-stage or more Sankey chart. https://vizdiff.blogspot.com/2020/01/creating-3-stage-sankey-chart-via.html

      Delete
  8. Thank you for this great template! I am running into a problem with dropping the sigmoid polygons onto the worksheets- any suggestions as to what I am doing wrong? Thank you again!

    ReplyDelete
    Replies
    1. Could you contact me at https://www.linkedin.com/in/alexmou/ ?

      Delete
    2. Try put "Path(bin)" on the Rows shelf first. Then right click on it and turn on "Show Missing Values". Last, move it from Rows to Details shelf. See if this works for you.

      Delete