> For the complete documentation index, see [llms.txt](https://docs.scanner.dev/scanner/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scanner.dev/scanner/using-scanner-complete-feature-reference/querying-and-analysis/aggregation-functions/percentile.md).

# 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

Return the median (value at the 50th percentile) of the `elapsed_ms` column.

```python
* | percentile(50, elapsed_ms)
```

Return the value at the 99.9th percentile of the `elapsed_ms` column.

```python
* | percentile(99.9, elapsed_ms)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
