Request a demo

BigQuery · Window function

BigQuery PERCENT_RANK

PERCENT_RANK() returns each row's relative rank in its window partition as a FLOAT64 from 0 to 1, computed as (rank - 1) / (rows - 1). Use it to say 'this request was slower than 90% of the others' or to flag the extreme rows of a group.

GoogleSQL for BigQuery · Checked against the official reference in November 2026

PERCENT_RANK is RANK rescaled to the range 0 to 1: (RANK - 1) / (rows in partition - 1). The first row of a partition gets 0, the last gets 1, and tied rows share a value because they share a rank. A partition with a single row returns 0.

Read the value as the share of the other rows that rank below the current one. With ORDER BY latency_ms, a PERCENT_RANK of 0.9 means 90% of the other requests were faster. Filter on it with QUALIFY, for example QUALIFY PERCENT_RANK() OVER (ORDER BY latency_ms) >= 0.9 for the slowest tenth.

ORDER BY is required and a window frame is not allowed. The related CUME_DIST counts the current row and its ties as well, so its smallest possible value is 1/n rather than 0. To get the value at a given percentile, rather than the percentile of each row, use PERCENTILE_CONT or APPROX_QUANTILES.

Syntax

PERCENT_RANK() OVER ([PARTITION BY partition_expression [, ...]] ORDER BY expression [{ASC | DESC}] [, ...])

Arguments and return value

ArgumentDescription
PARTITION BY partition_expressionComputes percent ranks within each group. Optional.
ORDER BY expressionRequired. The first row in this order gets 0, the last gets 1.

Returns: FLOAT64 between 0 and 1. 0 for a partition with one row.

Examples

Percent rank of order amounts

Five rows, so each step is 1/4. The two orders of 45 tie and share 0.25.

WITH orders AS (
  SELECT order_id, amount
  FROM UNNEST([STRUCT(1001 AS order_id, 20 AS amount), (1002, 45), (1003, 45), (1004, 80), (1005, 150)])
)
SELECT
  order_id,
  amount,
  PERCENT_RANK() OVER (ORDER BY amount) AS pct_rank
FROM orders
ORDER BY amount, order_id;
Result
order_idamountpct_rank
1001200.0
1002450.25
1003450.25
1004800.75
10051501.0

Per pipeline, including a one-row partition

WITH runs AS (
  SELECT 'orders_daily' AS pipeline, 1 AS run_id, 340 AS runtime_s UNION ALL
  SELECT 'orders_daily', 2, 410 UNION ALL
  SELECT 'orders_daily', 3, 380 UNION ALL
  SELECT 'users_sync', 4, 95
)
SELECT
  pipeline,
  run_id,
  runtime_s,
  PERCENT_RANK() OVER (PARTITION BY pipeline ORDER BY runtime_s) AS runtime_pct_rank
FROM runs
ORDER BY pipeline, runtime_s;
Result
pipelinerun_idruntime_sruntime_pct_rank
orders_daily13400.0
orders_daily33800.5
orders_daily24101.0
users_sync4950.0

Flag the slowest tenth of requests

WITH requests AS (
  SELECT request_id, latency_ms
  FROM UNNEST([
    STRUCT('r01' AS request_id, 120 AS latency_ms), ('r02', 95), ('r03', 310), ('r04', 88),
    ('r05', 102), ('r06', 2400), ('r07', 140), ('r08', 99), ('r09', 131), ('r10', 860), ('r11', 115)
  ])
)
SELECT
  request_id,
  latency_ms,
  PERCENT_RANK() OVER (ORDER BY latency_ms) AS pct_rank
FROM requests
QUALIFY pct_rank >= 0.9
ORDER BY latency_ms;
Result
request_idlatency_mspct_rank
r108600.9
r0624001.0

Common mistakes

  • Reading PERCENT_RANK as the share of rows at or below the current one. It starts at 0 and leaves the current row out; CUME_DIST includes it.
  • Trusting percent ranks of tiny partitions. With two rows the only values are 0 and 1, and one row always gets 0.
  • Expecting a threshold to select an exact share of rows. Ties share a value, so >= 0.9 can return more or fewer rows than 10%.
  • Omitting ORDER BY. PERCENT_RANK() OVER () fails with Window ORDER BY is required for analytic function percent_rank.

Cost and performance

  • Like other ranking functions, PERCENT_RANK without PARTITION BY sorts the whole input on one worker. On a large table, compute a percentile threshold once with APPROX_QUANTILES and compare each row with it.

FAQ

How do I calculate a percentile rank in BigQuery?

Use PERCENT_RANK() OVER (ORDER BY metric), or OVER (PARTITION BY group_col ORDER BY metric) per group. Multiply by 100 for a percentage.

What is the difference between PERCENT_RANK and CUME_DIST?

PERCENT_RANK is (rank - 1) / (n - 1) and starts at 0. CUME_DIST is the share of rows that come before the current row or tie with it, so it always counts the current row and is never 0.

How do I get the value at the 90th percentile instead?

Use PERCENTILE_CONT(x, 0.9) OVER () for an exact, interpolated value or APPROX_QUANTILES(x, 100)[OFFSET(90)] in a GROUP BY query. See PERCENTILE_CONT.

Errors you may hit

More window functions

All BigQuery window functions · All functions · BigQuery error messages

Observability for every BigQuery table, in about 15 minutes

Masthead detects freshness, volume and schema anomalies, monitors pipeline errors and maps column-level lineage across all your projects, from logs and metadata only.