---
title: 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`.
url: https://coralogix.com/docs/dataprime/language-reference/functions-reference/aggregation/percentile/
product: dataengine
feature: DataPrime Language
feature_id: dataprime-language
feature_identifier: dataengine/dataprime-language
last_updated: '2026-10-21'
---

# `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 |
