Available:slidingWindow() v1.174.0

The slidingWindow() function is available from version 1.174.0.

The slidingWindow() function applies an aggregation to a moving window of a specified number of events in a sequence. It is useful for calculating metrics over a fixed number of recent events, allowing for trend analysis and smoothing of data. For aggregating sliding windows based on time series span, see slidingTimeWindow() function.

For more information about sequence functions and combined usage, see Sequence Query Functions.

ParameterTypeRequiredDefault ValueDescription
currentenumoptional[a] include Controls whether to include the current event in the accumulation.
   Valid Values
   excludeExclude current event in the accumulation
   includeInclude current event in the accumulation
function[b]integerrequired   The number of events in each window.
  Maximum10001000 events
function[c]array of aggregate functionsrequired   The aggregator function(s) to apply to each window. It only accepts functions that output a maximum of one single event.

[a] Optional parameters use their default value unless explicitly set.

[b] The parameter name function can be omitted.

[c] The parameter name function can be omitted.

Hide omitted argument names for this function

Show omitted argument names for this function

Note

  • The slidingWindow() function must be used after an aggregator function (for example, head(), sort(), bucket(), groupBy() timeChart()) to ensure event ordering, as the accumulate() function requires a specific order to calculate cumulative values correctly.

  • Only functions (for example, sum(), avg(), count()) that output a single event can be used in the sub-aggregation because the slidingWindow() function needs a single value to add to its running total for each event.

Click + next to an example below to get the full details.

Detect Continuously Upwards Going Trend

Detect continuously upwards going trend using the slidingWindow() function combined with neighbor()