One-minute mini tutorial
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 SizeThere 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]
- {Fixed Dim: Max(1)}
-An extra column after union [Table Name]
Besides Source, Target & 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
View comments