# $avg

`$avg` operator helps you in calculating average of some values in an expression. You can use this in any [<mark style="color:blue;">**Expression Object**</mark>](https://docs.cosmocloud.io/flow-builder/cql-cosmocloud-query-language/building-expressions)

## Syntax

```json
{
    "$avg":[<expr>, <expr> ,....]
}
```

### Properties

| Field   | Description                                                                                                                                                                                                                     | Required |
| ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| \<expr> | <p>The <code>\<expr></code> expression can be any valid <a href=""><mark style="color:blue;"><strong>expression</strong></mark></a> as long as it resolves to a number.</p><p></p><p>It can also be a Magical Autocomplete.</p> | true     |

### Returns

`float` - The result of $avg operation

## Examples

### Basic example

```json
{
    "$avg": [1,2,3,4,5]
}
```

The above expression returns **3.0**

### With Nested Expressions

```json
{
    "$avg": [
        1,
        2,
        { "$add" : [1,2] },
        { "$pow" : [2,2] },
        5
    ]
}
```

The above expression calculates the nested expressions, return **3** and **4** respectively in its place and then the outer `$avg` expression returns **3.0** overall.

### With Magical Autocomplete

Let's say we have declared a variable `temp` of type array in our API flow, which has a value of &#x20;

\[ 2,4,8,2 ]  currently.

```json
{
    "$avg":"$.variables.temp"
}
```

The above expression would resolve to a result of **4**
