In this blog, you will learn about how to create Sankey chart in Tableau. A Sankey chart, also called a Sankey diagram, is a flow diagram used to show how resources, quantities, or information move between different stages or categories. Named after Irish engineer Matthew Sankey, who first used it in 1898, this chart is unique because the width of the arrows or flowchart reflects the size of the flow, making it easy to compare different paths.
Components of Sankey Chart in Tableau:
- Nodes: These are the different steps, categories, or units involved in the flow. They are usually shown in rectangular or circular shapes.
- Flows: Arrows or lines connecting nodes, whose width shows how much is being transferred from one node to another. The wider the flow, the larger the amount being transferred.
- Labels: These provide context, showing the names of the steps or categories and the size of each flow.
- Arrows: Indicate the direction of the flow, showing how things move from one step to another.
- Color coding: Different colors can be used to highlight different types of flows or categories, making the chart easier to understand.
Use Case of Sankey chart in Tableau:
- Clear visualization: Sankey charts clearly show how quantities move between different stages or categories, making it easy to see where the most critical flows are.
- Identifying inefficiencies: By mapping resource or information flows, Sankey charts help you identify bottlenecks or inefficiencies in a process.
- Exploring complex data: These charts are great for understanding the complex relationships between different components.
- Effective communication: The visual nature of Sankey charts makes it easy to explain complex data to others, ensuring everyone is on the same page.
- Trend analysis: Sankey charts can also be used to track how flows change over time, helping you monitor performance and identify trends.
Dataset description
The dataset includes sales information broken down by location, along with seven parameters: city, country, date, profit, region, sales, and segment. Utilizing these qualities, the dataset provides insights into regional profitability and consumer segmentation patterns. You can download the dataset from here.
Steps to create Sankey Chart in Tableau
Step 1: Open Tableau
Step 2: Click on Text file to connect with Tableau
Step 3: Browse csv file (or other file format as your need) and click on Open
Step 4: Click on Sheet 1 (Worksheet) to make visual
Step 5: Open Notepad and type the following as fig; select all and copy it
Step 6: Go back to tableau and paste using ctrl+v
Step 7: Click on Select a field from your table section and select Create Relationship Calculation…
Step 8: Type 1 and click on OK
Step 9: Click on Select a field from clipboard table section and select Create Relationship Calculation…
Step 10: Type 1 and click on OK
Step 11: Go to Sheet 1
Step 12: Rename Sheet 1 => sankey
Step 13: Right click on Path and select Create to select Bins…
Step 14: Type 1 in Size of bins and click on OK
Step 15: Click on Analysis tab and select Create Calculated Field…
Step 16: Type the following as mentioned in fig and hit OK
Step 17: Click on Analysis tab and select Create Calculated Field…
Step 18: Type the following as mentioned in fig and hit OK
Step 19: Right click over rank 1 and select Duplicate
Step 20: Again, right click over rank 1 and select Rename; rank 1 (copy) => rank 2
Step 21: Click on Analysis tab and select Create Calculated Field…
Step 22: Type the following as mentioned in fig and hit OK
Step 23: Click on Analysis tab and select Create Calculated Field…
Step 24: Type the following as mentioned in fig and hit OK
Step 25: Drag index over Columns, curve over Rows and Path (bin) over Details (under Marks card)
Step 26: Click on arrow of index and select Compute Using to select Path (bin)
Step 27: Click on arrow of curve and select Compute Using to select Path (bin)
Step 28: Drag Region and Segment over Detail
Step 29: Right click on Curve in Rows and select Edit Table Calculation…
Step 30: Select all and drag up-n-down to manage the sequence (as mentioned in pic)
Step 31: click on dropdown with rank 1 and select rank 2
Step 32: Select all and drag up-n-down to manage the sequence (as mentioned in pic)
Step 33: click on dropdown with Automatic and select Line
Step 34: Drag Segment (present in Marks card) over Path
Step 35: Right click on x-Axis header and select Edit Axis…
Step 36: Select Fixed; fill -5 in Fixed start and 5 in Fixed end
Step 37: Right click on x-axis header and click on Show Header to deselect
Step 38: Right click on y-axis header and click on Show Header to deselect
Step 39: Double click in Marks card at below of Path (bin) and type:
RUNNING_SUM(SUM([Sales]))
Step 40: Drag RUNNING_SUM(SUM([Sales])) over Size under Marks card
Step 41: Right click on RUNNING_SUM(SUM([Sales])) under Marks card and select Compute Using to select Path (bin)
Step 42: click on Size under Marks card and increase/decrease by sliding bar
Step 43: Click on detail icon at left of Region and select Color
Output of first Sheet (sankey):
Step 44: Right click on Sheet 2; select Rename to Source (optional)
Step 45: Double click in field of Rows and type as mentioned in fig
Step 46: Drag-n-drop Region over Color and Label
Step 47: Drag-n-drop RUNNING_SUM(SUM([Sales])) (from Rows) over Label
Step 48: Increase width to fit text in it easily
Step 49: Right click on RUNNING_SUM(SUM([Sales])) and select Format
Step 50: Select Currency (Custom) and select appropriate Unit
Step 51: Right click over vertical header and select Edit Axis…
Step 52: Select Reversed and close it
Step 53: Right click over vertical axis and select Show Header to deselect
Output of second Sheet (Source):
Step 54: Right click on Source Sheet and select Duplicate
Step 55: Right click on duplicated sheet and select Rename to Target
Step 56: Drop both Region under Marks card by drag-n-drop to Data section
Step 57: Drag-n-drop Segment over Color and Label under Marks card
Step 58: Click on Color and select Edit Colors…
Step 59: Select Gray in color palette and click on OK
Output of second Sheet (Target): click on new dashboard icon for next step
Step 61: Drag-n-drop sankey in work area
Step 62: Select Layout; unselect Show title and select Floating
Step 63: Delete legends by clicking cross icon
Step 64: Adjust size and position of visual
Step 65: Drag-n-drop Target sheet in work area
Step 66: Select Layout; unselect Show title and select Floating
Step 67: Adjust size and position of visual
Step 68: Delete legends by clicking cross icon
Step 69: Drag-n-drop Source sheet in work area
Step 70: Select Layout; unselect Show title and select Floating
Step 71: Adjust size and position of visual
Step 72: Delete legends by clicking cross icon
Step 73: Right click on sankey visual and select Format…
Step 74: Click on Lines icon; Select None in Grid Lines and Zero Lines
Step 75: click on Target visual and select None in Grid Lines and Zero Lines
Step 76: click on Color icon and select None in Worksheet
Step 77: Click on Source visual and select None in Worksheet
Step 78: Click on Lines icon; select None in Grid Lines, Zero Lines and Axis Rulers
Step 79: Click on Dashboard tab and select Actions…
Step 80: Click on Add Action and select Hightlight…
Step 81: Click on Hover; Select Source from Source Sheets and sankey from Target Sheets
Step 82: Again click on Add Action and select Highlight…
Step 83: Click on Hover; select Target from Source Sheets and sankey from Target Sheets
Step 84: Now finally click on OK
Output:
Note:
- Whenever user hover on Source or Target visual, all curved line will be fade except related lines
Conclusion:
Sankey charts are a powerful tool for visualizing resources, quantities, or information flow between different stages or categories. While Tableau does not have a built-in Sankey chart feature, you can still create one by following a few steps and using calculated fields. With the advanced features of Tableau, you can enhance your Sankey charts to provide detailed analysis, improve communication, and optimize data flow in various applications such as energy management, financial analysis, etc.
If you like the article and would like to support me, make sure to:
- 👏 Like for this article and subscribe to our newsletter
- 📰 View more content on my DataSpoof website
- 🔔 Follow Me: LinkedIn| Youtube | Instagram | Twitter