Skip to content

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

NameTypeRequiredDescription
expressionnumbertrueExpression 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

pathaverage_duration_for_path
/home500
/login200