# percentile()

`percentile(n, col)` returns the `n`-th percentile value of the provided column in the input datastream. A value at the `n`-th percentile means that `n`% of the values in the input datastream are below that value.

`n` must be a numeric value between 0 and 100. Floating point numbers are accepted.

If the provided column does not have numeric values or does not exist, `percentile` will return `null`; otherwise, `percentile` will always return a numeric value that was part of the input datastream.

## Technical Notes

* If there are at most 1000 values in the input stream, `percentile` uses the [nearest rank algorithm ](https://en.wikipedia.org/wiki/Percentile#The_nearest-rank_method)to return the exact value.
* If there are more than 1000 values in the input stream, `percentile` uses the [Karnin, Lang, and Liberty (KLL) algorithm ](https://arxiv.org/pdf/1603.05346.pdf)to return an approximation. The approximation is generally within 1% rank error, e.g. the value returned for the 90th percentile will usually be between the 89th and 91st percentile.

## Returns

A table with one row and one column, called `@q.value`.

## Examples

<pre class="language-python"><code class="lang-python"><strong># Return the median (value at the 50th percentile) of `elapsed_ms` column
</strong><strong>* | percentile(50, elapsed_ms)
</strong>
# Return the value at the 99.9th percentile of `elapsed_ms` column.
* | percentile(99.9, elapsed_ms)
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.scanner.dev/scanner/using-scanner-complete-feature-reference/querying-and-analysis/aggregation-functions/percentile.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
