TagAvg
- Last UpdatedSep 27, 2024
- 2 minute read
- PI System
- PI Server 2024 R2
- PI Server
Find the time-weighted or event-weighted average of values for an attribute during a specified time range.
Syntax
TagAvg(attname, starttime, endtime [, pctgood, calculationBasis])
Arguments
-
attname
attribute with time series data (such as PI point data reference) enclosed in single quotes
-
starttime
time expression representing the beginning of a time range enclosed in single quotes; can be a relative time (such as '-3h') in reference to an absolute endtime
-
endtime
time expression representing the end of a time range enclosed in single quotes; can be a relative time (such as '+1h') in reference to an absolute starttime
-
pctgood
Optional. Time-weighted or event-weighted minimum time percentage in a specified time range for which the attribute had good values
calculationBasis
Optional. A string indicating the type of calculation to be performed enclosed in double quotes. Choose between "TimeWeighted" or "EventWeighted". If omitted, the default is time-weighted
Returns
The time-weighted or event-weighted average of attribute values during a specified time range
Exceptions
If the point has no good values or the pctgood minimum is not reached for the given time range, returns an error value
Notes
-
Bad values are excluded from TagAvg calculation.
-
In order to configure an optional parameter, any previous optional parameter must be specified.
-
For more information, see the knowledge base article How Time-Weighted and Event-Weighted Totals and Averages Work.
Note: If the attribute has very few good values during the time range, this function's result may not be trustworthy. Use the PctGood function to find out what percentage of the values is good
Example
-
TagAvg('att1', 't', '+1h')
[Return the time-weighted average of values for 'att1' between 12:00 and 1:00am today]
-
TagAvg('att1', 't', '+1h', 80)
[Return the time-weighted average of values for 'att1' between 12:00 and 1:00am today when at least 80% of the values were good]
-
TagAvg('att1', 't', '+1h', 80, "EventWeighted")
[Return the event-weighted average of values for 'att1' between 12:00 and 1:00am today when at least 80% of the values were good]