--- title: "Sankey Diagram in Preset" slug: "sankey-diagram" description: "Description and usage of the Sankey Diagram chart in Preset Cloud." updated: 2023-10-13T18:51:46Z published: 2023-10-13T18:51:46Z canonical: "docs.preset.io/sankey-diagram" excludeFromSearch: true excludeFromExternalSearch: true --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.preset.io/llms.txt > Use this file to discover all available pages before exploring further. # Sankey Diagram ## Overview A Sankey diagram is a popular flow diagram that conveys the relative size of metric data based on the size of flow lines from a source to a target. Here is an example: ![](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/Screen%20Shot%202022-09-20%20at%206.50.14%20PM.png) ### Reference Content The following articles may be useful resources as you build your chart: - [Creating a Chart](/v1/docs/creating-a-chart): A walkthrough of the overall process of chart selection and creation. - [Using Preset Chart Builder](/v1/docs/using-preset-explore): How to work with the Chart Builder page, the primary interface used when creating a chart. ## Creating a Sankey Diagram Similar to a [tree chart](/v1/docs/tree-chart), a Sankey diagram uses nodes (represented visually as rectangles), edges (represented visually as flows), and hierarchy (left to right). Unlike a tree chart, the emphasis is on the flow between nodes instead of the hierarchy itself. The hierarchy represents stages in a system flow. **Shape of your Data** Structuring your data in the right shape is crucial for building effective Sankey diagrams. Let's zoom into a specific example of how a row in the dataset maps to a node-edge-node pair in the diagram. | ![](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/Group%2027.png) | - The **source** column specifies the originating node in the chart. - The **target** column specifies the receiving (or destination) node in the chart. - The **count** value is used to scale the thickness of the connecting flow rectangle. This value is also shown when a user hovers over the connecting flow rectangle. | | --- | --- | To scale this approach up and build a full Sankey diagram, Preset uses your data to calculate all of the **source-target** pairs and then orders them from left to right when generating the visualization. Which nodes go in the left-most column (or first layer of nodes) then? The unique values in the **source** column that ***aren't in the target column (or receive flow)*** end up in the first layer. Here's the full example: ![](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/Screen%20Shot%202022-09-20%20at%2010.59.05%20PM.png) Now we'll walkthrough the options we selected in Chart Builder and how the data was transformed: | ![](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/Screen%20Shot%202022-09-20%20at%207.50.35%20PM.png) | **Underlying Data** - Our data in this example is pre-aggregated in the *count* column. - The *source* and *target* columns map to the nodes we want visualized. | | --- | --- | | ![](https://cdn.document360.io/4749ddf8-aa05-4f3f-80e1-07a5d2d0f137/Images/Documentation/Screen%20Shot%202022-09-20%20at%2010.54.44%20PM.png) | **Chart Builder Options** - **Source / Target**: specify the column you want for the source nodes first and the column you want for the target nodes second. - **Metric**: specify the aggregate and column you want used for the thickness of the flow between the nodes | Here's the query that was generated: ```plsql SELECT source AS source, target AS target, sum(count) AS "SUM(count)" FROM main."Example: Sankey" GROUP BY source, target ```