How to create Sankey diagrams using Tableau?

As helpful Sankey charts are in helping improve the overall data visualization and energy flow, the same is not the easiest to create. There are certain tools that can make the process easier for you for if you are using Tableau, chances are that you will be able to overcome the process quite easily.

But, there are complications to that as well and there are chances that you will be confused amidst the process. That doesn’t mean that you can’t get the desired results from the same. To help you create the Sankey diagram on Tableau, we have sorted out some of the easy steps that you need to keep into consideration.

Keep in mind that the process is lengthy and it is going to be confusing. But, following through each and every single step can help clear the doubts and get the desired results in the end.

What is a Sankey diagram?

Before we share the steps, let us brief you on what Sankey diagram is. It is a energy flow diagram which helps in providing a clear illustration of the flow of the energy involved in a process.

It can very well include any element of energy or even money and finance flow in a process. It depends on what one needs to visualize.

What is Tableau?

With Sankey diagram of the out way, let us talk about Tableau. Tableau is an online data visualization software that helps in better understanding and layout of your database in a diagrammatic form.

This helps in better understanding of the loopholes and the roadblocks that need to be mended.

It was Jeffrey Shafer from the Tableau community who piloted the techniques for drawing a Sankey chart in Tableau. Later, it was Olivia Katherine who worked further on the same and expanded on it for better efficiency. Even Chris Love further perfected the steps made by Noah Salvaterra and Joe Mako that made this process complete and wholesome.

Steps to follow for drawing Sankey chart using Tableau

To be honest, there are several sections and roundabouts when it comes to making a Sankey chart using Tableau but we are going to give you a complete rundown of all the steps one after the other that you need to follow.

It is a lengthy one but trust us, if you follow through them blindly, it won’t be a difficult process for you. Just ensure that you have a basic coding knowledge and know how to use Tableau.

  1. Open Tableau.
  2. Select your excel file from the desired location on your computer. You can import it accordingly
  3. Drag your data sheet (which you want), and you will want to make a copy of the available data because that is how it demands to be done on Tableau to compensate for the both hands of the chart.
  4. Navigate to Data > Convert to custom SQL. A pop-up window will be displayed.
  5. In the pop-up window, copy and paste the code below it. Write UNION ALL in between the two codes
  6. In the first code, write “Segment” as VizSide before FROM keyword
  7. In the second code, write “Region” as VizSide before FROM keyword
  8. Click OK
  9. Now, navigate to Sheet 1, at the bottom
  10. Right click on the Measure section and click on Create calculated field. Then, name it as “ToPad”
  11. Now paste the following code: IF [VizSide]= “Segment” THEN 1 ELSE 49 END
  12. Click OK. ToPad menu will be displayed in the Measure section. (The reason why “49” is specifically used is because Jeffrey Shafer suggested that this arbitrary number is beneficial in helping form that swish curve line that is significant in the Sankey chart.)
  13. Drag ToPad to the Columns in the right hand side
  14. Hover it and an arrow will be displayed. Click on it.
  15. Select Dimension. Repeat step 11 and select Discrete.
  16. Drag the ToPad from column to the left hand side and it will disappear from column section
  17. Navigate to ToPad > Create > Bins
  18. Rename New field name as Padded. Size of bins as 1. Click OK. It will be shown in Dimension section
  19. Right click on Measure section and click on Create calculated field. Name it as t.
  20. Now paste the following code: (INDEX()-25)/4
  21. Click OK. t menu will be displayed in the Measure section
  22. Drag t to the Columns in the right hand side
  23. Hover it and an arrow will be displayed. Click on it.
  24. Select Discrete. Repeat step 11 and select Continuous.
  25. Drag Padded from Dimension section to Marks section
  26. Click on t and navigate to Compute Using > Padded
  27. Right click on Measure section and click on Create calculated field. Name it as Rank 1
  28. Now paste the following code: RUNNING_SUM(SUM([Sales]))/TOTAL (SUM([Sales]))
  29. Click OK. Rank 1 menu will be displayed in the Measure section
  30. Click on Rank 1 menu and select Duplicate. Rename it as Rank 2
  31. Right click on Measure section and click on Create calculated field. Name it as Sigmoid
  32. Now paste the following code: 1/(1+EXP(1)^-[t])
  33. Click OK. Sigmoid menu will be displayed in the Measure section
  34. Right click on Measure section and click on Create calculated field. Name it as Curve
  35. Now paste the following code: [Rank1]+(([Rank2]-[Rank1])*[Sigmoid])
  36. Click OK. Curve menu will be displayed in the Measure section
  37. Drag Curve to the Rows in the right hand side
  38. Drag Segment and Region to the Marks section in the right hand side
  39. Click on Curve(in the Rows section, in the right hand side) and click Edit table Calculation
  40. Select Rank 1 in Nested Calculation and click Specific Dimension
  41. Rearrange: Segment, Region, Padded. Check all the boxes
  42. Select Rank 2 in Nested Calculation and click Specific Dimension
  43. Rearrange: Region, Segment, Padded. Check all the boxes
  44. Right Click on the chart area. Click Format
  45. Select Line icon and change Grid lines and Zero lines to none
  46. Click on the BottomRuler of the graph
  47. Click Edit Axis
  48. Check Fixed. Set Fixed start : -5 and Fixed end : 5.
  49. Click on the Left side Ruler of the graph
  50. Click Edit Axis
  51. Check Fixed. Set Fixed start : 0 and Fixed end : 0. Check Reverse in Scale section
  52. Click on the Left side Ruler of the graph
  53. Uncheck Show header
  54. Click on the BottomRuler of the graph
  55. Uncheck Show header
  56. Close Format lines in the left hand side
  57. Drag Padded from Dimension section to Marks section
  58. Select Line in Marks section
  59. Navigate to Analyze > Create Calculated field. Rename it as Sales Sizing
  60. Now paste the following code: WINDOW_AVG(SUM([Sales]))
  61. Click OK. Sales Sizing menu will be displayed in the Measure section
  62. Drag Sales Sizing from Measure section to the Marks section in the right hand side
  63. Click on SalesSizing (in Marks section) and Compute Using > Padded.
  64. You can change the color of segment, region, padding as per your choice, by clicking on the left icon of each in the Marks section.

As complicated as the process seems, trust us, it only requires for you to follow through the steps. The process can take some time but make sure that you follow the steps as mentioned. Once the chart is completed, it is completely on you how you manage and customize the same. This is a very basic breakdown on how to draw a Sankey chart using Tableau.

Leave A Reply

Your email address will not be published.