Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Faggregation%2Fpercentile.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Faggregation%2Fpercentile.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `percentile`

## Description

Returns the approximate n-th percentile of a numerical expression.

* The percentile value must be between `0` and `1`.
* The calculation is approximate, with accuracy controlled by the optional `error_threshold`.

## Syntax

```
percentile(percentile: number, expression: number, error_threshold: number?): number
```

## Arguments

| Name              | Type     | Required  | Description                                                                              |
| ----------------- | -------- | --------- | ---------------------------------------------------------------------------------------- |
| `percentile`      | `number` | **true**  | Percentile to compute, between `0` and `1`                                               |
| `expression`      | `number` | **true**  | Numerical expression whose percentile is calculated                                      |
| `error_threshold` | `number` | **false** | Accuracy of approximation. Lower values are more accurate but slower. Defaults to `0.01` |

## Example

**Use case: Calculate the 99th percentile of trace durations**

Suppose you want to compute the 99th percentile latency for Lambda function invocations.

### Example data

```
{ "operationName": "Lambda.Invoke", "duration": 95000 },

{ "operationName": "Lambda.Invoke", "duration": 500000 },

{ "operationName": "Lambda.Invoke", "duration": 1100000 },

{ "operationName": "Lambda.Invoke", "duration": 1482000 },

{ "operationName": "CheckoutFlow", "duration": 800000 }
```

### Example query

```
source spans

| filter $l.operationName == 'Lambda.Invoke'

| groupby $l.operationName aggregate percentile(0.99, $m.duration) as p99_latency
```

### Example output

| operationName | p99\_latency      |
| ------------- | ----------------- |
| Lambda.Invoke | 1482198.478333334 |
