How to Calculate Percentiles in BigQuery
Last updated August 30, 2026 · By the SaturnSQL team
Use PERCENTILE_CONT(col, p) OVER () for an exact interpolated percentile, PERCENTILE_DISC for an actual stored value, or APPROX_QUANTILES(col, 100) to compute every percentile in one cheap aggregate pass.
SELECT DISTINCT PERCENTILE_CONT(latency_ms, 0.95) OVER () AS p95
FROM requests;All the percentiles in one pass
APPROX_QUANTILES(col, 100) returns a 101-element array where element N is the Nth percentile. One aggregate scan gives you p50, p95, and p99 together, and unlike PERCENTILE_CONT it works inside GROUP BY. The trade-off is approximation: fine for dashboards and monitoring, not for a compliance report.
SELECT
quantiles[OFFSET(50)] AS p50,
quantiles[OFFSET(95)] AS p95,
quantiles[OFFSET(99)] AS p99
FROM (
SELECT APPROX_QUANTILES(latency_ms, 100) AS quantiles
FROM requests
);Percentiles per group
SELECT
endpoint,
APPROX_QUANTILES(latency_ms, 100)[OFFSET(95)] AS p95
FROM requests
GROUP BY endpoint
ORDER BY p95 DESC;PERCENTILE_CONT vs PERCENTILE_DISC
PERCENTILE_CONT interpolates between the two nearest values, so it can return a number that never occurs in the column. PERCENTILE_DISC returns the nearest actual value instead, which matters for discrete data like plan prices or integer scores.
Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free