Contribute in GitHub:
Edit online

# avgif() (aggregation function)

Calculates the average of *Expr* across the group for which *Predicate* evaluates to `true`

.

- Can only be used in context of aggregation inside summarize

## Syntax

`avgif`

`(`

*Expr*`,`

*Predicate*`)`

## Arguments

*Expr*: Expression that will be used for aggregation calculation. Records with`null`

values are ignored and not included in the calculation.*Predicate*: predicate that if true, the*Expr*calculated value will be added to the average.

## Returns

The average value of *Expr* across the group where *Predicate* evaluates to `true`

.

## Examples

```
range x from 1 to 100 step 1
| summarize avgif(x, x-2 == 0)
```

### Results

avgif_x |
---|

2 |