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

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

```json
{ "path": "/home", "duration": 400 },
{ "path": "/home", "duration": 600 },
{ "path": "/login", "duration": 200 }
```

### Example query

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

### Example output

| path   | average_duration_for_path |
| ------ | ------------------------- |
| /home  | 500                       |
| /login | 200                       |
