Skip to main content

Hi everyone, 

I’m building a Sankey chart in Tableau and I’m struggling with the correct percentage labels for each level. 

My data structure is a pre-aggregated funnel table with these fields: 

  • ds
  • Step1
  • Step2_Filter
  • Step2
  • Step3
  • Step4
  • users
  • Table Name

  

The Sankey is built using duplicated rows via Table Name: 

 

  • Orders
  • Orders1

  

Then I use a Path calculation to create the left/right side of the polygon: 

 

// Path

IIF([Table Name] = {MIN([Table Name])}, 0, 97)

  

Path is then converted to Path (bin) with bin size 1. 

  

The funnel logic is roughly like this: 

 

  • Step1: No Order / With Order
  • Step2_Filter: Card / Pip
  • Step2: Pip Enabled / Pip Disabled / Card Enabled / Card Disabled
  • Step3: ... → Pip Confirm, ... → Card Confirm, ... → No Confirm
  • Step4: ... → Purchased, ... → Lost after Confirm, or NULL for No Confirm

  

Example filtered view: 

 

Step1 = No Order

Step2_Filter = Pip

  

Then the first visible split is: 

 

Pip Enabled

Pip Disabled

  

I want the labels to show users and percentages correctly at each level: 

 

  1. For Step2, I need each branch as a percentage of the selected base:

 

Pip Enabled / (Pip Enabled + Pip Disabled)

Pip Disabled / (Pip Enabled + Pip Disabled)

 

  1. For Step3, I need each branch as a percentage of its parent Step2 node:

 

Pip Enabled → Pip Confirm / Pip Enabled

Pip Enabled → No Confirm / Pip Enabled

Pip Enabled → Card Confirm / Pip Enabled

 

  1. For Step4, I need each branch as a percentage of its parent Step3 node:

 

Pip Enabled → Pip Confirm → Purchased / Pip Enabled → Pip Confirm

Pip Enabled → Pip Confirm → Lost after Confirm / Pip Enabled → Pip Confirm

  

The Sankey polygon itself works, but the percentage labels are incorrect because the view has multiple technical dimensions: 

 

  • Path (bin)
  • Table Name
  • Step2
  • Step3
  • Step4
  • table calculations like INDEX(), RUNNING_SUM(), WINDOW_MAX()

  

Because of this, when I try to calculate percentages in Tableau, the denominators are either duplicated or calculated at the wrong partition level. 

  

Current core Sankey calculations: 

 

// Flow Size

SUM([users]) * (1 - [Whitespace]) / TOTAL(SUM([users]))

// Position-L

RUNNING_SUM([Flow Size]) - [Flow Size] + [Whitespace L]

// Position-R

RUNNING_SUM([Flow Size]) - [Flow Size] + [Whitespace R]

// Curve Max Win

[Position Max Win L] + ([Position Max Win R] - [Position Max Win L]) * [Sigmoid]

// Curve Min Win

[Position Min Win L] + ([Position Min Win R] - [Position Min Win L]) * [Sigmoid]

// Curve Polygon Win

IIF(INDEX() >= 50, [Curve Min Win], [Curve Max Win])

  

For label positioning I currently use something like: 

 

// Label

IF [t] = 6 THEN WINDOW_MAX([Bar Position]) END

  

What I need help with: 

  

How should I calculate the correct denominators for each Sankey level so that: 

 

  • Step2 % = Step2 users / selected base users
  • Step3 % = Step3 users / parent Step2 users
  • Step4 % = Step4 users / parent Step3 users

  

Should this be done in Tableau using table calculations, or is it better to pre-calculate parent denominators in SQL and only use Tableau for rendering? 

  

If SQL pre-calculation is the better approach, what grain should the SQL output have to work correctly with Tableau Sankey densification? 

  

How to calculate correct parent-level percentages in a Tableau Sankey chart with Path bins and duplicated rows?

 

 

 

#Tableau Cloud

0/9000