Totalizer that resets to 0 with Asset based Analytics
I need to calculate a running sum (totalizer) of a PI Point and reset it to 0 at the beginning of each month. I would like to do this with Asset based Analytics. There are workarounds to do this, but none are great. For example, one workaround involves an intermediate PI Point and another work around does not work with backfilling.
There is this request already on user voice: https://feedback.osisoft.com/forums/555148-pi-server/suggestions/17442598-event-weighted-summary-functions
This isn't exactly what I'm looking for because I need my total to be reset periodically (1 month in my specific case).
@Kenneth Barber I tried something similar with TagTot('attribute', 't', '*') to totalize over one day and had the following two issues: 1. TagTot does not reset the value to zero at the start of the new timeframe ('t' in my case), and 2. When the start and end are the same time, i.e. '*' = 't', then a calc fail is thrown if 'attribute' has a value at that right at 't'.
Kenneth Barber commented
Try something like this:
where 'attribute' is the attribute that is being totalized.
Bom is a function that returns the beginning of the month. TagTot is a totalizer function (more precisely, it calculates the definite integral of an attribute between a start time and an end time). TagTot assumes that the given attribute is some sort of rate per day, (e.g. liters per day, tonnes per day), so you may need to multiply the result by a conversion factor.
If your attribute does not represent rates and instead represents the individual values to be summed, you will need to do this:
TagMean('attribute',Bom('*'),'*') * EventCount('attribute',Bom('*'),'*')
See this thread: https://pisquare.osisoft.com/thread/7591
Explanation: TagMean sums the values of all events in a given time range and then divides by the number of events. Multiplying by EventCount of the same attribute over the same time range undoes the division, leaving us with only the summation.
These approaches are much more concise than, say, this (pseudocode):
current totalizer value = 0 if the month changed, otherwise previous totalizer value + change since the previous totalizer value