How to Make a Sankey Diagram in Tableau

Cody Schneider

Sankey diagrams are a fantastic way to visualize the flow of data, showing how a value is distributed from one set of categories to another. While Tableau doesn't offer a one-click Sankey option, you can absolutely build a beautiful and insightful one yourself. This tutorial will walk you through the entire process step-by-step, from structuring your data to customizing the final chart.

What Exactly is a Sankey Diagram?

Think of a Sankey diagram as a flow map. The width of the lines, or “flows,” is proportional to the quantity being represented, making it immediately obvious where the largest contributions or transfers are. They’re excellent for answering questions that involve movement, funnels, or contributions.

You can use them to visualize things like:

  • Website Traffic: How users flow from acquisition channels (Organic, Social, Paid) to different landing pages (Homepage, Blog, Products).

  • Customer Journeys: The path customers take from a free trial to different subscription tiers.

  • Budget Allocation: How a company’s budget is distributed from departments to specific projects.

  • Marketing Funnels: How leads move from one stage of the funnel to the next.

The diagram consists of two main parts: the nodes (the categories on the left and right, often represented as bars) and the links (the flowing curves connecting the nodes). The bigger the link, the larger the value it represents.

Data Preparation: The Foundation of Your Sankey

The key to building a Sankey in Tableau isn’t some hidden setting, it’s all in how you prepare your data. Because we need to draw smooth curves, we need to artificially create more data points between the start and end of each flow. This technique is often called data densification.

1. Your Original Data Source

First, you need your core data. Let's imagine we're analyzing website traffic. Your data should be simple and have at least three columns: a starting dimension, an ending dimension, and a measure of the value flowing between them.

For example, in a Google Sheet or Excel file, it might look like this:

Source Data (e.g., 'Traffic_Data.xlsx')

  • Traffic Source (e.g., 'Organic', 'Paid Search', 'Social Media')

  • Landing Page (e.g., 'Homepage', 'Blog Post', 'Pricing Page')

  • Sessions (e.g., 5000, 3200, 1500)

2. The 'Densification' Model

Next, we need a separate model to create the points for our curves. In a new tab in your spreadsheet, create a single column named "Path" with numbers from 1 to 99.

Model Data (e.g., in a separate sheet called 'Model')

  • Path (a single column with rows numbered 1, 2, 3, ... all the way to 99)

Why 99 points? This gives us enough data points to plot a smooth curve for each flow in our original dataset.

3. Joining the Data in Tableau

Now, connect to your spreadsheet in Tableau. We will join these two tables together in a very specific way.

  1. Drag your primary data table ('Traffic_Data') onto the canvas.

  2. Drag your model table ('Model') onto the canvas.

  3. Tableau will try to create a relationship. Click the join noodles to open the join configuration.

  4. Instead of joining on a common field, select "Create Join Calculation" on the left side, enter the number 1, and hit Enter.

  5. Do the same on the right side. The join clause should be 1 = 1.

This type of join tells Tableau to connect every row from your traffic data to every row in your model data. So, for a single flow like 'Organic' to 'Homepage', you now have 99 rows instead of one. You’ve successfully densified your data!

Building the Sankey: Calculated Fields Galore

With the data structure in place, the rest of the work happens in a Tableau worksheet through a series of calculated fields. Don't worry about the math - focus on creating them correctly, and it will all come together.

Step 1: Create the 't' Field for Positioning

This field normalizes our 'Path' from 1-99 to a range of -4.9 to 4.9. This range will be fed into a curve-generating function.

Calculated Field Name: t

Step 2: Create the Sigmoid Curve Function

A sigmoid function creates a beautiful 'S' shape. This calculation will take our t value and use it to plot the gentle curve we're looking for.

Calculated Field Name: Sigmoid

Step 3: Calculate the Position of Flows (The 'Sankey Arm')

Now for the most important calculation. This field figures out the exact vertical (Y-axis) position for every point of our curve. It calculates the starting height of the flow on the left bar and the ending height on the right bar, then uses our Sigmoid function to fill in all the points in between.

Calculated Field Name: Sankey Arm Y

Note: The formula above is conceptual. The fields [Position of Start Node] and [Position of End Node] are not standard fields, you'll replace those with your actual measures, often implemented via running sums related to your measure. For clarity, let's build the complete, usable field that incorporates those inside.

Here's a simpler structure that works, using your measures directly:

Calculated Field Name: Sankey Polygon

Let's simplify and use one of the well-established formulas from Tableau experts, as these calculations are complex and highly specific. Here's a more straightforward, functional approach:

Correct Calculated Fields:

1. To Pad:Create a bin for your Path data. Right-click on Path in the data pane, select Create > Bins..., and set the size to 1. This new field will be Path (bin).

2. t:

3. Sankey Curve:

4. Sankey Arm Position:

This set of calculations is intricate! But it’s the basis to position and transition the curves properly. Trust the process—building the visual will clarify the logic.

Putting It All on the Canvas

Step 1: Build the Initial Viz

  1. Drag the t calculated field to Columns. Right-click it and ensure it is a Continuous Dimension.

  2. Drag Sankey Arm Position to Rows.

  3. Drag Path (bin) to Detail on the Marks card. Right-click and ensure "Show Missing Values" is checked. This prompts Tableau to fill in gaps for densification.

  4. Change the Mark Type from Automatic to Line.

  5. Drag your first dimension (Traffic Source) and second dimension (Landing Page) to Detail on the Marks card, beside Path (bin). You should see many lines—this is expected!

  6. Drag Path to the Path card on the Marks shelf.

Step 2: Configure the Table Calculations

  1. Right-click the Sankey Arm Position pill on the Rows shelf and select Edit Table Calculation.

  2. Set it to compute using a Specific Dimension.

    • Check both Traffic Source and Landing Page, and also Path (bin).

    • Drag the dimensions so that Traffic Source is on top in the nested calculations.

  3. Ensure the nested calculations (like RUNNING_SUM, WINDOW_SUM) are partitioned appropriately depending on the specific formula needs. This often involves some trial and error.

Proper configuration will organize the lines into the layered curves characteristic of a Sankey diagram.

Step 3: Add the Bars (Nodes) with a Dual Axis

  1. Create two new calculated fields:

    • Name: Bar Position LeftFormula: 0

    • Name: Bar Position RightFormula: 0

  2. Drag Bar Position Left onto the Rows shelf, next to Sankey Arm Position.

  3. Right-click Bar Position Left and select Dual Axis.

  4. For each axis, adjust chart type:

    • For Bar Position Left, set Mark Type to Bar.

    • For Bar Position Right, do the same.

  5. Assign the relevant dimensions (Traffic Source, Landing Page) to Detail on each respective Bar mark.

  6. Assign measures (Sessions) to Size on each respective bar and adjust widths as needed to give a solid bar appearance.

  7. Repeat for the right node side if applicable, or handle them on separate worksheets for cleaner implementation.

Final notes on bar placement:

Many advanced Sankey implementations create separate worksheets for the left and right bars, then overlay them in a dashboard for perfect alignment.

Customizing and Refining Your Chart

Once the basic structure is in place:

  • Coloring: Drag your starting dimension (Traffic Source) to Color for the lines to encode origin.

  • Flow Size: Create a calculated field like SUM([Sessions]), and drag to Size for the flows. Apply table calculations (along Path) for proportional curves.

  • Tooltips: Customize tooltips to show origin, destination, and session count.

  • Labels: Add labels on your node bars indicating category names and totals. Synchronize axes for neatness.

Final Thoughts

Creating a Sankey diagram in Tableau is a rewarding challenge. It involves careful data shaping with densification and nested calculations, but results in a powerful visualization of flow and distribution. As you gain experience, you'll better understand Tableau's advanced calculation capabilities.

While custom Sankey charts are great, sometimes you need quick insights. We built Graphed because we believe data insights shouldn't require complex setups. Connect tools like Google Analytics or prompt natural-language questions, and get real-time, automated Sankey visualizations—without manual calculation or configuration. Focus on decisions, not the chart-building process.