Using aggregation functions in formula expressions - Amazon IoT SiteWise
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Using aggregation functions in formula expressions

In metrics only, you can use the following functions that aggregate input values over each time interval and calculate a single output value. Aggregation functions can aggregate data from associated assets.

Aggregation function arguments can be variables, number literals, temporal functions, nested expressions, or aggregation functions. The formula max(latest(x), latest(y), latest(z)) uses an aggregation function as an argument and returns the largest current value of the x, y, and z properties.

You can use nested expressions in aggregation functions. When you use nested expressions, the following rules apply:

  • Each argument can have only one variable.

    For example, avg(x*(x-1)) and sum(x/2 )/avg(y^2 ) are supported.

    For example, min(x/y) isn't supported.

  • Each argument can have multilevel nested expressions.

    For example, sum(avg(x^2 )/2) is supported.

  • Different arguments can have different variables.

    For example, sum(x/2, y*2) is supported.

Note
  • If your expressions contain measurements, Amazon IoT SiteWise uses the last values over the current time interval for the measurements to compute aggregates.

  • If your expressions contain attributes, Amazon IoT SiteWise uses the latest values for the attributes to compute aggregates.

Function Description

avg(x0, ..., xn)

Returns the mean of the given variables' values over the current time interval.

This function outputs a data point only if the given variables have at least one data point over the current time interval.

sum(x0, ..., xn)

Returns the sum of the given variables' values over the current time interval.

This function outputs a data point only if the given variables have at least one data point over the current time interval.

min(x0, ..., xn)

Returns the minimum of the given variables' values over the current time interval.

This function outputs a data point only if the given variables have at least one data point over the current time interval.

max(x0, ..., xn)

Returns the maximum of the given variables' values over the current time interval.

This function outputs a data point only if the given variables have at least one data point over the current time interval.

count(x0, ..., xn)

Returns the total number of data points for the given variables over the current time interval. For more information about how to count the number of data points that meet a condition, see Counting data points that match a condition.

This function computes a data point for every time interval.

stdev(x0, ..., xn)

Returns the standard deviation of the given variables' values over the current time interval.

This function outputs a data point only if the given variables have at least one data point over the current time interval.