I believe tagtot you used should be from PI PE function. However, in the description of this function in PEReference, it says this function is used to "Find the totalized value (time integral) of a point over a given time, according to values stored in the Archive." The red words, time integral, in the description means this function used time-weighted way to calculate total. If you need the event-weighted way to do the calculation, PI SDK / AF SDK function should be considered. Please see the help menu of PI SDK. The function is under PI DATA part named as Summary method.
Please see the following code as the reference:
PISDK.PISDK pi_sdk = new PISDK.PISDK(); Server pi_server = pi_sdk.Servers["WIN-01ARJPPGTEJ"]; PIPoint point = pi_server.PIPoints["cdt158"]; PITimeFormat start_time = new PITimeFormat(); start_time.InputString = "*-30d"; PITimeFormat end_time = new PITimeFormat(); end_time.InputString = "*"; PIValue value = point.Data.Summary(start_time, end_time, ArchiveSummaryTypeConstants.astTotal, CalculationBasisConstants.cbEventWeighted);
As Xi mentioned, the tagtot() function is really finding the time integral value for the given time range based on the values stored in the archive for the tag. In layman's term, it is finding the area under the graph. So you want to consider for your total calculation, would time-weighted total be appropriate, or it is better to use an event-weighted total.
Xi gave a code snippet that will get event-weighted total in PI SDK. But If you are looking for something in PE syntax that will give that, there isn't a PE function that does that directly. You can do something like tagmean('tagname', '*-30d', '*') * eventcount('tagname', '*-30d', '*') instead
tagmean() function calculates the mean of the tag's value (in another words, the event weighted average), and multiplying it by count of events will give the total.
Another thing that you want to take note for time-weighted total calculation is conversion factor. Without the appropriate conversion factor setting, time-weighted total calculation results from tagtot function may give the wrong result. What this does and why we need to consider a conversion factor is explained in this video on our youtube learning channel.
This is from the help file,
The system chooses a scale factor such that the integral will be correct only if the flow is expressed in units per day. If the flow is expressed in units per hour, or per some other time unit, you must multiply this result by a conversion factor. The conversion factor equals the number of actual flow time units in a day.
For instance, if you totalize a point measured in gallons per minute, you must multiply the result of TagTot by 1440 to get the answer in gallons. This conversion factor is not related to the time period you are totalizing over; it is strictly a function of the point's engineering units.
It sounds to me like a conversion factor. If you are reading KWH then *24. Hope that helps
Thanks all for your help. I have used the tagmean function (tagmean('tagname', '*-30d', '*') * eventcount('tagname', '*-30d', '*') as mentioned by Han and I'm getting the results I require. Once again thanks for your help.