Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Faggregation%2Favg.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%2Favg.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `avg`

## Description

Returns the average (mean) value of a numerical expression.

Note

The input must be a number. Use a cast if the field is stored as a string.

## Syntax

```
avg(expression: number): number
```

## Arguments

| Name         | Type     | Required | Description                           |
| ------------ | -------- | -------- | ------------------------------------- |
| `expression` | `number` | **true** | Expression that evaluates to a number |

## Example

**Use case: Compute the average HTTP request latency per path**

Suppose you want to calculate the average request duration for each URL path in your logs.

### Example data

```
{ "path": "/home", "duration": 400 },

{ "path": "/home", "duration": 600 },

{ "path": "/login", "duration": 200 }
```

### Example query

```
groupby $d.path aggregate avg($m.duration) as average_duration_for_path
```

### Example output

| path   | average*duration*for\_path |
| ------ | -------------------------- |
| /home  | 500                        |
| /login | 200                        |
