# Enable Notifications Need help with APAMA or EPL in calculating daily average

**URL:** <https://community.cumulocity.com/t/enable-notifications-need-help-with-apama-or-epl-in-calculating-daily-average/7431>\
**Category:** Forum\
**Tags:** Streaming-Analytics-Apama, cumulocity\
**Created:** [August 30, 2022, 11:16am UTC](https://community.cumulocity.com/t/enable-notifications-need-help-with-apama-or-epl-in-calculating-daily-average/7431 "2022-08-30T11:16:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhassan](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/mhassan/32/4078_2.png) [@mhassan](https://community.cumulocity.com/u/mhassan)\
**Post date:** [August 30, 2022, 11:16am UTC](https://community.cumulocity.com/t/enable-notifications-need-help-with-apama-or-epl-in-calculating-daily-average/7431/1 "2022-08-30T11:16:59Z")

</div>

#### What product/components do you use and which version/fix level are you on?

10.11.25

#### Is your question related to the free trial, or to a production (customer) instance?

production

#### What are you trying to achieve? Please describe it in detail.

My measurement data is flowing to a device in Cumulocity every minute. I need to create a new measurement in the same device which shows the daily average of my measurement (one data point everyday) . Can I use APAMA or EPL apps to do this logic? Any suggestion how to achieve this?

#### Do you get any error messages? Please provide a **full error** message screenshot and log file.

#### Have you installed all the latest fixes for the products and systems you are using?

---

<div class="post-metadata">

**Author:** ![Kai\_Sieben](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/kai_sieben/32/5541_2.png) [@Kai\_Sieben](https://community.cumulocity.com/u/Kai_Sieben)\
**Post date:** [August 30, 2022, 2:48pm UTC](https://community.cumulocity.com/t/enable-notifications-need-help-with-apama-or-epl-in-calculating-daily-average/7431/2 "2022-08-30T14:48:54Z")

</div>

Hi @mhassan,

here is an example for an Analytics Builder Model calculating an average. In this case it is an average per minute.  
That should help you get started.  
Be aware that a model should always create data in a separate measurement-type, otherwise it is looping the data to itself.  
[Average.zip](https://community.cumulocity.com/uploads/short-url/uOzfMXGxxEGh7MjAwfaDBlUnMba.zip) (944 Bytes)

Regards  
Kai

---

<div class="post-metadata">

**Author:** ![anon19830398](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@anon19830398](https://community.cumulocity.com/u/anon19830398)\
**Post date:** [August 30, 2022, 6:34pm UTC](https://community.cumulocity.com/t/enable-notifications-need-help-with-apama-or-epl-in-calculating-daily-average/7431/4 "2022-08-30T18:34:28Z")

</div>

Hi Saif,

Yes that is absolutely possible.

If you wanted a ‘sliding window’ type metric where the average is updated on each new measurement, you can use streams and queries.

```auto
// Declare a global variable to hold the result of the average calculation

float avg;

// This stream calculates the average over a 24h sliding window

stream<Measurement> measurements := from m in all Measurement(source=source) within 86400.0 select mean(m.value):avg {};

// Then send the measurement once per day using cron notation (using midnight as an example)

on all at (0,0,*,*,*) {
    send Measurement(..., avg, ...) to Measurement.SEND_CHANNEL;
}

```

Alternatively, if you aren’t bothered about the exact time of day that the average is output as a measurement, you can make use of batched windows to evaluate and output the average every 24 hours after startup. This has the advantage of not requiring a global variable and being a shorter and more elegant solution while lacking the fine grained control of the one above.

```auto
from m in all Measurement(source=source) within 86400.0 every 86400.0 select mean(m.value) : avg {
    send Measurement(..., avg, ...) to Measurement.SEND_CHANNEL;
}

```

Some doc links with more detail:  
[This page in the Cumulocity docs](https://cumulocity.com/guides/apama/examples/#hourly-mean) shows a similar example for calculating the mean of the last hour.  
[This page in the Apama documentation](https://documentation.softwareag.com/apama/v10-11/apama10-11/apama-webhelp/index.html#page/apama-webhelp%2Fta-DevApaAppInEpl_defining_batched_windows.html%23) describes how to batch events in EPL.  
[This page in the Apama documentation](https://documentation.softwareag.com/apama/v10-11/apama10-11/apama-webhelp/index.html#page/apama-webhelp%2Fco-DevApaAppInEpl_about_timers_and_their_trigger_times.html) shows how you can use time based triggers like the cron one above.  
[This page in the Apama documentation](https://documentation.softwareag.com/apama/v10-11/apama10-11/apama-webhelp/index.html#page/apama-webhelp%2Fta-DevApaAppInEpl_defining_time_based_windows.html%23) describes how to define time based windows in stream queries.
