Aggregate Functions

Functions that produce aggregates over multiple data points.

Aggregate functions require that the dashboard columns without aggregate functions have a grouping level applied. The aggregate function will then be evaluated against the values in the group.

Average

Takes an average value of the arguments

average(arg)
mean(arg)

Examples

average(${val})
${val} = [10, 20, 30, 40]
> 25
mean(${val})
${val} = [10, 20, 30, 40]
> 25

Count

Counts the number of records that are passed through it. Doesn’t take any notice of the values of any fields.

count()

Example

Supplying 3 values...

count()
> 3

Count Groups

This is used to count the number of unique group keys where there are multiple group levels. For example, a data set grouped as follows

  1. Group by Name
  2. Group by Type

countGroups could be used to count the number of distinct values of ’type’ for each value of ’name'.

countGroups()

Count Unique

This is used to count the number of unique values passed to the function where grouping is used to aggregate values in other columns. For Example, a data set grouped as follows

  1. Group by Name
  2. Group by Type

countUnique() could be used to count the number of distinct values of ’type’ for each value of ’name'

Example

countUnique(${val})
${val} = ['bill', 'bob', 'fred', 'bill']
> 3

Distinct

Concatenates all distinct (unique) values together into a single string. Works in the same way as joining() except that it discards duplicate values. Values are concatenated in the order that they are given to the function. If a delimiter is supplied then the delimiter is placed between each concatenated string. If a limit is supplied then it will only concatenate up to limit values.

distinct(values)
distinct(values, delimiter)
distinct(values, delimiter, limit)

Examples

distinct(${val}, ', ')
${val} = ['bill', 'bill', 'bob', 'fred', 'bill']
> 'bill, bob, fred'
distinct(${val}, '|', 2)
${val} = ['bill', 'bill', 'bob', 'fred', 'bill']
> 'bill|bob'

Joining

Concatenates all values together into a single string. Works in the same way as distinct() except that duplicate values are included. Values are concatenated in the order that they are given to the function. If a delimiter is supplied then the delimiter is placed between each concatenated string. If a limit is supplied then it will only concatenate up to limit values.

joining(values)
joining(values, delimiter)
joining(values, delimiter, limit)

Example

joining(${val}, ', ')
${val} = ['bill', 'bob', 'fred', 'bill']
> 'bill, bob, fred, bill'

Lag

Gives the value that an aggregate has in an earlier time window of the same group, for a StroomQL query with a window clause.

lag(aggregate, windows)
lag(aggregate, windows, default)
  • aggregate - An aggregate, such as count() or sum(${Bytes}), or the name of an eval or column that is one.
  • windows - How many windows earlier, as a whole number from 1.
  • default - The value to give when the earlier window has no value. It can’t start with window:.

The earlier window is a number of window sizes before the row’s own, whatever the advance. An earlier window with no events for the group gives the empty value of the aggregate, which is 0 for count(). An earlier window that is before the first window of the search that has events gives no value, or default if it is given.

Examples

# With 'window EventTime by 1d', and 4 events on Monday and 10 on Tuesday
# For the row of Tuesday
lag(count(), 1)
> 4
count() - lag(count(), 1)
> 6
# For the row of Monday, the first day that has events
lag(count(), 1)
> null
lag(count(), 1, 0)
> 0

Lead

Gives the value that an aggregate has in a later time window of the same group, for a StroomQL query with a window clause.

lead(aggregate, windows)
lead(aggregate, windows, default)
  • aggregate - An aggregate, such as count() or sum(${Bytes}), or the name of an eval or column that is one.
  • windows - How many windows later, as a whole number from 1.
  • default - The value to give when the later window has no value. It can’t start with window:.

This works as lag() does, but reads the window a number of window sizes after the row’s own.

Example

# With 'window EventTime by 1d', and 4 events on Monday and 10 on Tuesday
# For the row of Monday
lead(count(), 1)
> 10

Max

Determines the maximum value given in the args.

max(arg)

Examples

max(${val})
${val} = [100, 30, 45, 109]
> 109
# They can be nested
max(max(${val}), 40, 67, 89)
${val} = [20, 1002]
> 1002

Min

Determines the minimum value given in the args.

min(arg)

Examples

min(${val})
${val} = [100, 30, 45, 109]
> 30
# They can be nested
min(max(${val}), 40, 67, 89)
${val} = [20, 1002]
> 20

StDev (Standard Deviation)

Calculate the standard deviation for a set of input values.

stDev(arg)

Examples

round(stDev(${val}))
${val} = [600, 470, 170, 430, 300]
> 147

Sum

Sums all the arguments together

sum(arg)

Examples

sum(${val})
${val} = [89, 12, 3, 45]
> 149

Variance

Calculate the variance of a set of input values.

variance(arg)

Examples

variance(${val})
${val} = [600, 470, 170, 430, 300]
> 21704