Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to

Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website

Meta script for calculating the current years monthly totals for a given point.

  • Looking for a solution in Mango 2.8 Meta Script.
    I have a kilowatt/hour meta point that I sample once an hour.
    I need to sum up the total kWh usage for each month for the current year to date (ie. Jan '18 through today's last kWh entry.) Any guidance would be appreciated.

  • Hi raylatbasix,

    You should be able to achieve this with a meta point like,

    1. Update event: start of month
    2. kWh point in context, but not producing updates, named p
    TIMESTAMP=CONTEXT.getRuntime()-1;  //the last millisecond of the previous month, would appear as a value on Feb 1 instead of Jan 31 without this
    // would use TIMESTAMP = CONTEXT.getTimestamp()-1 in the current version, as runtime is when the script actually runs
    return p.past(MONTH).sum;

    And then use the history generation tool on the "Data points" tab in the edit data source area. This button: 0_1534448135759_yc46yet7.bmp

  • Awesome Phil!! I will give this a try! Thanks for the help!

  • Hi Phil,

    This looks like it's working!! Just one more question. Is there any way to rollup the data so there is only one row per month in the dataset? Right now, it shows the same monthly sum total for every kWh hourly entry for each month, which equals over 283,000 rows. Do you know how to just display one row per month showing the total?

    Thanks Again!

  • That sounds like you left your update event on "Context update" instead of "Start of month" or you did get the update event right, but the point in the context is still checked to produce context update events.

  • Hi Phil,
    Sorry for the late reply. Just checked my settings for both meta points. My originating kWh meta point is set up for "Start of Hour" on update event, and the "Updates context" checkbox is unchecked for the modbus kW point (p40). I generate my kWh calculation from my modbus kW point as follows:

    var stats = p40.past(HOUR, 1);
    if(stats.count !== 0) return stats.average;
    return 0;

    My new Meta point is setup "Start of Month" for update event, and "Updates context" is unchecked for my kWh meta point (p130) as well. My code:

    return p130.past(MONTH).sum;

    Like I said, it seems to calculate monthly totals ok, Just looking for a way to "Rollup" the data rows to 1 monthly total per month. Thanks again.

  • Hmm. I tested my suggestion on 2.8 (meta 2.3), and only got one value per month, so, that should have worked. Do you have the meta point set to interval log every hour?

    You could remove it from the context and do something like,

    var dprt = com.serotonin.m2m2.Common.runtimeManager.getDataPoint( 130 );
    if( dprt != null ) {
      var p = new com.serotonin.m2m2.rt.script.NumericPointWrapper( dprt, null, null );
      return p.getStats( CONTEXT.getRuntime() - CONTEXT.millisInPast(MONTH) -1, CONTEXT.getRuntime() ).sum;
    return -1;

    But then, I did test the first solution before proffering it.

  • Boy, do I feel stupid!! It was the Logging Interval!! All set now!

    Thanks for putting up with me!!

  • No worries, glad it's working for ya!