Streaming Analytics - Time-based Moving Average

Cumulocity 10.15 Analytics Builder

I want to calculate a time-based moving average in analytics builder. The reason is that the data explorer truncates the data due to too many datapoints in the selected time window.
If I use the aggregate function in the data explorer, I can only choose between min/max values every minute/hour/day.

I want to calculate a time-based moving average in the analytics builder that reduces the number of datapoints based on the selected time interval.


I want to calculate the average of an input stream for a time window of 1 hour. I want the analytics builder to send me only one value for the selected time window (30 mins, 1 hour, …) which is the average of the datapoints it receives as input.

The default average function doesn’t work

The default average function in analytics builder calculates a rolling average with the same number of datapoints as the original input stream; thus, I end up receiving the same truncated data problem with the original input stream.

Did someone build such a time-based moving average in analytics builder and can help me with my issue?


the default blocks (“Average (Mean)” and “Discrete Statistics”) have a “Sample” input. If it is connected, the block will only produce an output if the “Sample” input is active. You could for example use the “Cron Timer” block to create the aggregations in a fixed interval.


Hi Harald

The Cron timer works partially. I want it to tick an output every 30 minutes. But I can only set the either to a full date, which is too coarse or every 60 seconds, which is too short. Am I understanding the cron timer wrong? Is it possible to set the timer to 30 minutes?


This is the way I connected the blocks. In the cron timer I tried using the default 0 for seconds and * / 30 in the minutes section. But as soon as the pulse is out the first time, the function will continuously send out the values together with the new input values form the input stream.

Glad you figured out how to set it to every 30 min. I think it is supposed to work like you modelled it. Let me test myself.

I didn’t get the 30 minute timer to work. It just send the average values at the same time as the input values. We connected the cron timer to the “send” of the output block, which now activates the output in the set interval. But not in 30 minute intervals but only within the seconds intervals.

Ok, I think this is just the behavior of the “Average (Mean)” block that it will produce an output for every input unless you have configured an output threshold.

I was successful when using the Discrete Statistics block instead which only produces an output if the “Sample” input becomes active:

1 Like

Possibly also try with a Gate?
See this previous forum post - maybe it helps:
Is it possible to develop a cron-triggered delta calculation with Analytics Builder? - Forum - Cumulocity IoT - Software AG Tech Community & Forums

1 Like

This works as intended. We could either connect the cron timer to the Send input of the output block when using the average block or connect the cron timer to the input of the discrete statistics, which will calculate the average between the intervalls of the cron timers. The solutions with the discrete block is more elegant. Thanks!

Hi Kevin
This is also possible. The discrete solution is more elegant as I only need to adjust the time interval in the cron timer and nowhere else. It’s a simple more fool-proof solution. I will use the delta calculation in another case, which is also really helpful, thanks!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.