Function table / Aggregates / PERCENTILE

PERCENTILE: from Tableau to SQL

Returns a linearly interpolated percentile of non-null values. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

PERCENTILE([amount], 0.25)

Sample data

idamountunitsscoreother
1-2.52-0.83
20004
31.530.252
4440.58
5950.811
6166114
7null7null9
848-0.5null

The same calculation as SQL

SELECT quantile_cont(amount,0.25) AS result FROM input

Runs the example above.

Result

result
0.75

Same rows from the calculation and from the SQL in DuckDB.

Where a naive translation goes wrong

  • Replacing missing observations with zero changes the aggregate.

    Naive SQL

    SELECT quantile_cont(coalesce(amount,0),0.25) AS result FROM input
    result
    0

    Matches the calculation

    SELECT quantile_cont(amount,0.25) AS result FROM input
    result
    0.75

Signature

PERCENTILE(number, percentile)