One-minute mini tutorial

A project at work requires to create Sankey charts for various data sets. Yes, people just love Sankey charts. Unfortunately it's a rather complex chart to create from scratch.

I found my early effort 1, 2 don't create Sankeys as nice as I wanted. Then I fell on Ken Flerlage's Sankey template, which is based on the earlier works of Jeffrey Schaffer and Olivier Catherin. Yes, that's what I am looking for, because I will hand over it to someone who is a beginner in Tableau. Greatly inspired by Ken's work, I went on to create a simpler template as described here. Now I believe that anyone with basic Tableau skills can create Sankey charts in case of need. It is as easy as 1-2-3. Here are the 3 steps:

1.Connect your data source from the Sankey Template Workbook
Download the template here.

2.Union your data table with itself
This doubles the size of your data set.

3.Rename fields and replace data source
Rename 2 dimensions & 1 measure as Source, Target Size. Then replace the template data source by yours.

Voila. You are done with your new Sankey chart.

You can stop here. Continue if you wish to know more details.

Postscripts

-Using CountD(Dim) or [Number of Records] as Size
There are a few use cases where people want to represent Number of Records by Size. Then just create this calculated field for the measure Size:
  • [Number of Records]
In another case, the user wants to use CountD(Dim) as Size. However, Size has to be a record level measure, then we must write the following calculated field as Size:
  • {Fixed Dim: Max(1)}
Sum() of the above field is equivalent of CountD(Dim).

-An extra column after union [Table Name]
Besides SourceTarget Size, the Sankey chart needs an extra column Table Name. It is auto generated by union within Tableau. This field is to identify the upper and lower tables in the union. You can do the union outside of Tableau but you need to always creating this Table Name column in your script.

-When data source is other than flat file
The above method assumes data is in a flat file such as Excel or CSV. Depending on your data source, you can union your data table in SQL, Python or R. Then create data set directly with 4 required field names: Source, Target, Size and an extra one Table Name (auto-generated by Tableau union. If not Tableau, we need to add it). Please populate the last column Table Name with 'table1' and 'table2'.

Below is a simple SQL snippet: (add aggregation via group by if you wish.)
Select Dim1 as Source, Dim2 as Target, Measure as Size, 'table1' as [Table Name] From Data
Union
Select Dim1 as Source, Dim2 as Target, Measure as Size, 'table2' as [Table Name] From Data

Then all you need to do is replace the data source. Extract the data source and automate the viz if you wish.

-Minimize data set size
For Sankey chart, all we need is actually 4 fields: Source, Target, Size and an extra Table Name (auto-generated by Tableau union). After union, drag them to a blank sheet, then hide the unused the fields and extract the data. We will get a data extract with 4 fields only. The data pane in Tableau will look a lot cleaner. Data extraction can be a bit faster.

That's it. Enjoy Tableau! BTW, I would be glad to know if this works for you.

PS.
To create a third level, just cascade 2 Sankey charts in dashboard:
https://vizdiff.blogspot.com/2020/01/creating-3-stage-sankey-chart-via.html

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
62

View comments

  1. Works perfect! Thank you so much for sharing!

    ReplyDelete
  2. I want to add a third level to the template, so I duplicated and modified every calculated field and everything was good until I had to create the new curve, I modified Curve A Polygon Win 2 in this way: IIF(INDEX()>=50, [Curve A Min Win 2],[Curve A Max Win 2]) but it didn't work.

    ReplyDelete
    Replies
    1. Send me the workbook Alexandermou2000@g

      Delete
    2. I faced the exact same issue. I didn't modify Curve A, but for Curve B I used IIF(INDEX()>=50, [Curve B Min Win],[Curve B Max Win])

      It is not working! Thanks in advance for your help Alexander.

      Delete
    3. Trying to modify the template is not so easy. The calculation there is fairly complicated. Send me your workbook and write a note about what you want to achieve. @gmail.com

      Delete
  3. Hi, my stacked bar on the left isn't aligning to the sankey. I'm not sure why. How can I fix this?

    ReplyDelete
    Replies
    1. can't do much without seeing the workbook. If you wish, send it to my gmail with succinct description: alexandermou2000@g.

      Delete
  4. This is fantastic Alex. Building out Sankey's in Tableau from scratch is slow and complicated. With this template you can have a result in seconds. Loved it.

    ReplyDelete
  5. Hi Alex, thank you for this fantastic an easy to use template. I see people tried to add a third level ... may it be possible that you publish a 3 level sankey?

    ReplyDelete
    Replies
    1. Just cascade two sankey's and you will have a 3-level one.

      Delete
  6. Thank you Alex!
    Is it possible do it on tableau public ?

    ReplyDelete
  7. Thanks Alex. Are these templates royalty free?

    ReplyDelete
  8. Hi Alex - Thanks! Again, Is it also possible that you publish a third level and provide some option where the user could add more levels as per the requirements.

    ReplyDelete
    Replies
    1. You can cascade two sheets to make it happen.

      Delete
    2. Here is the tutorial on creating a 3-stage Sankey https://vizdiff.blogspot.com/2020/01/creating-3-stage-sankey-chart-via.html

      Delete
  9. Hello, excellent visual! Much faster than building from scratch. Thank you. Quick question: is it possible to edit the color scheme of the curves?

    ReplyDelete
    Replies
    1. Yes. Just go ahead and edit the colors in the template.

      Delete
  10. Hello, Thank you for your prompt response. Unfortunately, in the template I have tried via row banding, column banding and a few others without success.

    Its not the most important detail. What would be neat to do is if I could move the a category, from Target, up or down. For example, right now, category "Strongly Agree" is in the middle of the categories and I would like to move it to the top and then have "Strongly Disagree". Is this possible or can it only be done in the coding?

    Thanks!

    ReplyDelete
  11. Didn't work for me. The bar charts did but the curves in the middle didn't.

    ReplyDelete
  12. Is it possible to create a Sankey in Tableau that merely tracks a COUNT of records from one side to the other? For example could a Sankey show the flow of users between Status1 and Status2 if you data was structured like:

    Name Status1 Status2
    Bob Active Closed
    Alice Active Active
    Frank Closed Pending
    Matt Pending Active
    Susan Closed Active
    George Closed Closed

    ReplyDelete
    Replies
    1. Absolutely. let Status1=Source, Status2=Target, Countd(Name)=Size give it a try and let us know if it works.

      Delete
  13. thank you for sharing, looks perfect,
    but in my case it gives error of Path(bin), after replacing it doesn't recognize the Path(bin). please if you guide why this happening and how to resolve it. thanks

    ReplyDelete
    Replies
    1. Could you send me your workbook with description of the problem? you can find my email in the comment area above.

      Delete
    2. Faced same issue, error in Path formula which only taking Table instead of Table Name (which has a red exclamation mark)

      Delete
    3. Make sure both data sources have the same field name: either Table Name or Table. Rename one to be exactly the same as the other, before replacing the data source. Don't forget to self-union your data source first.

      Delete
    4. Hi Alexander - I am having the same issue with Path(bin). When I try to replace it, it does not update and rather keeps the old version of Path(bin). Can you please advise?

      Delete
  14. The newest version and the 3-stage is excellent.

    I was wondering if the Target categories can be manually sorted after the sankey is produced? I have ordinal categories that seem to get arbitrarily mixed once in the sankey form. Thank you.

    ReplyDelete
    Replies
    1. Yes. Right click on Target pill and select sort. Let me know if that works for you. You have to sort Target the same way on every worksheet which has the dimension Target.

      Delete
    2. Thank you! This is huge. It is a great teaching tool for my students when teaching categorical data.

      Delete
    3. Another approach, go to the dimension panel and right click on Target>Default Properties>Sort. This will define the sorting once for all sheets. Try it and see if this works better. BTW, if you don't mind, where do you teach?

      Delete
    4. The "Target>Default Properties>Sort" method is what I had done as I couldn't see any other way of doing it. This is what I thought you originally had meant. And it worked perfect.

      I (Brent Marinan) teach both Marketing and Statistics at the University of Arizona. I previously only built Sankeys (from scratch) myself and had used it only as a teaching-tool/illustration. With your template, I can now put the tool in the students hands and they can build their own Sankey (doing it from scratch would be too much for them).

      Something of note: With the categorical survey data, I rename "record count" with "Size". Unfortunately, thought, the 2020 Tableau desktop versions remove the ability to rename this measure. So I just use the 2019.4 version.

      Delete
    5. Strange. Try renaming Size as "record count" instead. As long as field names are identical in both data sources, it should work. BTW, try 2020.2 instead of 2020.1.

      Delete
    6. The other way of sorting is sort the dimension pill on canvas per worksheet. Right click the pill and select sort. This will alter the default sort.

      Delete
    7. Unfortunately, no luck renaming Size nor any luck with 2020.2 Desktop. I am good with the earlier version though.

      One question: I tried to save it to Tableau Public (via Server) but an error came up mentioning it needed to be extracted. If its possible, what would be the process to be save it to Tableau Public?

      Delete
    8. To save (publish) it in Tableau Public, you need to always extract data source first. Then save/publish the workbook to the server. Since it's a public server, many people are publishing their workbooks to it. Extracts will save storage capacity.

      Delete
    9. Okay, makes sense. A first, simple one published with your template. Lots still to learn. Thank you again.

      https://public.tableau.com/profile/brentm5539#!/vizhome/FrequencyofVisitbyGender/SankeyChartTemplate

      Delete
  15. Hi, does it allow a filtering using dimensions other than "Target" and "Source"?

    ReplyDelete
    Replies
    1. Yes. Regular dimension filters will work as usual.

      Delete
  16. Hi, how do I download the template? When I click on the link above and download the workbook, I cannot open it.
    Thank you,
    Lorenzo

    ReplyDelete
    Replies
    1. Did you download the latest Tableau Public and install it in your computer?

      Delete
  17. Hi Alex, I've tried with a simple dataset and the bars at the side appeared but not the curves in the center. Could you provide some guidance please? Thank you!

    ReplyDelete
  18. Hi Alex, I've tried with a simple dataset and the bars at the side appeared but the curves in the center didn't. Could you provide some guidance please? Thank you!

    ReplyDelete
    Replies
    1. Did you follow the steps, especially the first: union the data source by itself?

      Delete
  19. is there a way to get horizontal bars for the left/right charts with labels?

    ReplyDelete
    Replies
    1. Since the vertical bars is on a sheet. You can replace them by your custom horizontal bars at the dashboard level.

      Delete
  20. Did you union the data table with itself? In SQL you need to add an extra column “Table Name” which denotes the upper and lower tables as t1 and t2. Try with an static excel table first.

    ReplyDelete

(Refresh the page if you want to view the gif image multiple times. Or go to Tableau Public and click the button at the top-right corner.)

Jake and I collaborated on a dashboard. He told me that he learnt a way to create an in-place help page in Tableau. He first saw it at a conference somewhere and couldn't recall who the speaker was. So I am blogging here about it but the credit goes to somebody else. If anyone knows who the original creator is, leave a comment below.

The key idea is to float a semi transparent worksheet on top of the dashboard, where a help text box is strategically placed on top of each chart. This way, we can explain how to view each chart and what data points are important, etc. This worksheet is collapsible by a show/hide button. 

Below I would like to show how this worksheet can be constructed.

1. Sheet with a single data mark.

  • Double click the empty space in Marks panel and add two single quotes. Make the null pill a text label. This creates a single null mark.
  • Set the view as "Entire View"

2. Create an show/hide button

  • Go to the target dashboard
  • Drag a floating vertical container to the dashboard, making it cover all the area of interest.
  • Drag the Single Null Mark sheet and drop it into the above container. Hide the sheet title.
  • Create an open/close button for the container and place the button at the top-right corner.

3. Add annotations

  • Format the sheet background opacity as 70% in the layout manager             
  • Select area annotations and place them anywhere of interest. 
  • Write help text and format it to highlight important messages.  
  • The text can serve as functional guide and/or insight guide.

Here is an example. Feel free to download the workbook and explore. Click the "i" button at the top-right corner to view the in-place help. 

0

Add a comment

Blog Archive
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.