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

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