CUME_DIST

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Returns the cumulative distribution of the current row within its partition.

Syntax 

1cume_dist() OVER ( [ PARTITION BY <expression> [, ...] ] ORDER BY <expression> [, ...] )

Arguments 

cume_dist takes no arguments. It depends on the ORDER BY clause within OVER to determine row order. For full details on the OVER clause and window frames, see Window Functions. For details on naming a window definition with a WINDOW clause, see SELECT.

Returns 

Returns a double precision value calculated as (number of partition rows preceding or peer with the current row) / total partition rows. cume_dist computes the fraction of partition rows that are less than or equal to the current row and its peers.

Considerations 

  • Requires ORDER BY in the OVER clause. Without ORDER BY, all rows are treated as peers and the result isn’t meaningful.
  • The result range is greater than 0, up to and including 1. The last row (or tied group of last rows) in each partition always gets a cume_dist of 1.
  • Rows with equal ORDER BY values are peers and receive the same cume_dist.

Examples 

Cumulative Distribution by Group 

Calculate each employee’s cumulative salary distribution within their department.

1SELECT depname, empno, salary, cume_dist() OVER (PARTITION BY depname ORDER BY salary)
2FROM empsalary;

The highest-salaried employee in each department (or the tied group of highest earners) returns a cume_dist of 1 since all rows in the partition are preceding or peer with that row.

Cumulative Distribution Across All Rows 

Omit PARTITION BY to calculate the cumulative distribution across the entire result set.

1SELECT empno, salary, cume_dist() OVER (ORDER BY salary)
2FROM empsalary;

Related Documentation