[comment]: # translation:outdated

[comment]: # ({new-ee60e21e})
# 1 Aggregate functions

Except where stated otherwise, all functions listed here are supported
in:

-   [Trigger expressions](/manual/config/triggers/expression)
-   [Calculated items](/manual/config/items/itemtypes/calculated)

Aggregate functions can work with either:

-   history of items, for example, `min(/host/key,1h)`
-   [foreach functions](/manual/appendix/functions/aggregate/foreach) as
    the only parameter, for example, `min(last_foreach(/*/key))`

Some general notes on function parameters:

-   Function parameters are separated by a comma
-   Optional function parameters (or parameter parts) are indicated by
    `<` `>`
-   Function-specific parameters are described with each function
-   `/host/key` and `(sec|#num)<:time shift>` parameters must never be
    quoted

[comment]: # ({/new-ee60e21e})

[comment]: # ({new-4d343eb8})
##### Common parameters

-   `/host/key` is a common mandatory first parameter for the functions
    referencing the host item history
-   `(sec|#num)<:time shift>` is a common second parameter for the
    functions referencing the host item history, where:
    -   **sec** - maximum [evaluation
        period](/manual/config/triggers#evaluation_period) in seconds
        (time [suffixes](/manual/appendix/suffixes) can be used), or
    -   **\#num** - maximum [evaluation
        range](/manual/config/triggers#evaluation_period) in latest
        collected values (if preceded by a hash mark)
    -   **time shift** (optional) allows to move the evaluation point
        back in time. See [more
        details](/manual/config/triggers/expression#time_shift) on
        specifying time shift.

[comment]: # ({/new-4d343eb8})

[comment]: # ({new-ad86e84b})
#### Aggregate functions

|FUNCTION|<|<|<|
|--------|-|-|-|
|<|**Description**|**Function-specific parameters**|**Comments**|
|**avg** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Average value of an item within the defined evaluation period.|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>Examples:<br>=> **avg**(/host/key,**1h**) → average value for the last hour until [now](/manual/config/triggers#evaluation_period)<br>=> **avg**(/host/key,**1h:now-1d**) → average value for an hour from 25 hours ago to 24 hours ago from [now](/manual/config/triggers#evaluation_period)<br>=> **avg**(/host/key,**\#5**) → average value of the five latest values<br>=> **avg**(/host/key,**\#5:now-1d**) → average value of the five latest values excluding the values received in the last 24 hours<br><br>Time shift is useful when there is a need to compare the current average value with the average value some time ago.|
|**bucket\_percentile** (item filter,time period,percentage)|<|<|<|
|<|Calculates the percentile from the buckets of a histogram.|**item filter** - see [item filter](/manual/appendix/functions/aggregate/foreach#item_filter)<br>**time period** - see [time period](/manual/appendix/functions/aggregate/foreach#time_period)<br>**percentage** - percentage (0-100)|Supported only in calculated items.<br><br>This function is an alias for `histogram_quantile(percentage/100, bucket_rate_foreach(item filter, time period, 1))`|
|**count** (func\_foreach(item filter,<time period>))|<|<|<|
|<|Count of values in an array returned by a foreach function.|**func\_foreach** - foreach function for which the number of returned values should be counted (with supported arguments). See [foreach functions](/manual/appendix/functions/aggregate/foreach) for details.|Supported value type: int<br><br>Example:<br>=> **count**(max\_foreach(/\*/net.if.in\[\*\],1h)) → number of net.if.in items that received data in the last hour until [now](/manual/config/triggers#evaluation_period)<br><br>Note that using **count()** with a history-related foreach function (max\_foreach, avg\_foreach, etc.) may lead to performance implications, whereas using **exists\_foreach()**, which works only with configuration data, will not have such effect.|
|**histogram\_quantile** (quantile,bucket1,value1,bucket2,value2,...)|<|<|<|
|<|Calculates the φ-quantile from the buckets of a histogram.|**quantile** - 0 ≤ φ ≤ 1<br>**bucketN, valueN** - manually entered pairs (>=2) of parameters or response of [bucket\_rate\_foreach](/manual/appendix/functions/aggregate/foreach)|Supported only in calculated items.<br><br>Functionally corresponds to '[histogram\_quantile](https://prometheus.io/docs/prometheus/latest/querying/functions/#histogram_quantile)' of PromQL.<br><br> Returns -1 if values of the last 'Infinity' bucket (*"+inf"*) are equal to 0. <br><br>Example:<br>=> **histogram\_quantile**(0.75,1.0,last(/host/rate\_bucket\[1.0\]),"+Inf",last(/host/rate\_bucket\[Inf\])<br>=> **histogram\_quantile**(0.5,bucket\_rate\_foreach(//item\_key,30s))|
|**item\_count** (item filter)|<|<|<|
|<|Count of existing items in configuration that match filter criteria.|**item filter** - criteria for item selection, allows referencing by host group, host, item key, and tags. Wildcards are supported. See [item filter](/manual/appendix/functions/aggregate/foreach#item_filter) for more details.|Supported value type: int<br><br>Works as an alias for the *count(exists\_foreach(item\_filter))* function.<br><br>Example:<br>=> **item\_count**(/\*/agent.ping?\[group="Host group 1"\]) → number of hosts with the *agent.ping* item in the "Host group 1"|
|**kurtosis** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|"Tailedness" of the probability distribution in collected values within the defined evaluation period.<br><br>See also: [Kurtosis](https://en.wikipedia.org/wiki/Kurtosis)|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>Example:<br>=> **kurtosis**(/host/key,**1h**) → kurtosis for the last hour until [now](/manual/config/triggers#evaluation_period)|
|**mad** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Median absolute deviation in collected values within the defined evaluation period.<br><br>See also: [Median absolute deviation](https://en.wikipedia.org/wiki/Median_absolute_deviation)|See [common-parameters](#common parameters).|Supported value types: float, int<br><br>Example:<br>=> **mad**(/host/key,**1h**) → median absolute deviation for the last hour until [now](/manual/config/triggers#evaluation_period)|
|**max** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Highest value of an item within the defined evaluation period.|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>Example:<br>=> **max**(/host/key,**1h**) - **min**(/host/key,**1h**) → calculate the difference between the maximum and minimum values within the last hour until [now](/manual/config/triggers#evaluation_period) (delta of values)|
|**min** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Lowest value of an item within the defined evaluation period.|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>Example:<br>=> **max**(/host/key,**1h**) - **min**(/host/key,**1h**) → calculate the difference between the maximum and minimum values within the last hour until [now](/manual/config/triggers#evaluation_period) (delta of values)|
|**skewness** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Asymmetry of the probability distribution in collected values within the defined evaluation period.<br><br>See also: [Skewness](https://en.wikipedia.org/wiki/Skewness)|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>Example:<br>=> **skewness**(/host/key,**1h**) → skewness for the last hour until [now](/manual/config/triggers#evaluation_period)|
|**stddevpop** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Population standard deviation in collected values within the defined evaluation period.<br><br>See also: [Standard deviation](https://en.wikipedia.org/wiki/Standard_deviation)|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>Example:<br>=> **stddevpop**(/host/key,**1h**) → population standard deviation for the last hour until [now](/manual/config/triggers#evaluation_period)|
|**stddevsamp** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Sample standard deviation in collected values within the defined evaluation period.<br><br>See also: [Standard deviation](https://en.wikipedia.org/wiki/Standard_deviation)|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>At least two data values are required for this function to work.<br><br>Example:<br>=> **stddevsamp**(/host/key,**1h**) → sample standard deviation for the last hour until [now](/manual/config/triggers#evaluation_period)|
|**sum** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Sum of collected values within the defined evaluation period.|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>Example:<br>=> **sum**(/host/key,**1h**) → sum of values for the last hour until [now](/manual/config/triggers#evaluation_period)|
|**sumofsquares** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|The sum of squares in collected values within the defined evaluation period.|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>Example:<br>=> **sumofsquares**(/host/key,**1h**) → sum of squares for the last hour until [now](/manual/config/triggers#evaluation_period)|
|**varpop** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Population variance of collected values within the defined evaluation period.<br><br>See also: [Variance](https://en.wikipedia.org/wiki/Variance)|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>Example:<br>=> **varpop**(/host/key,**1h**) → population variance for the last hour until [now](/manual/config/triggers#evaluation_period)|
|**varsamp** (/host/key,(sec\|\#num)<:time shift>)|<|<|<|
|<|Sample variance of collected values within the defined evaluation period.<br><br>See also: [Variance](https://en.wikipedia.org/wiki/Variance)|See [common parameters](#common-parameters).|Supported value types: float, int<br><br>At least two data values are required for this function to work.<br><br>Example:<br>=> **varsamp**(/host/key,**1h**) → sample variance for the last hour until [now](/manual/config/triggers#evaluation_period)|

[comment]: # ({/new-ad86e84b})
