Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

Analytics and Notifications for PI System Explorer (PI Server 2024 R2)

Avg

  • Last UpdatedJan 11, 2023
  • 2 minute read

Return the time-weighted or event-weighted average from a set of one or more values.

Syntax

Avg(x1 [, ... xn])

Avg(array [, calculationBasis])

Arguments

  • x1, ... xn

    Arguments or a single array of same value type (integers and real numbers, time expressions, or time intervals)

  • calculationBasis

    Optional. The type of calculation to be performed enclosed in double quotes. Choose between "EventWeighted" or "TimeWeighted." If omitted, the default is event-weighted. If you select "TimeWeighted," the earliest timestamp of the value marks the start time and the latest timestamp the end of a time range

Returns

The average of one or more values. The result is of the same data type as arguments

Exceptions

Arguments whose run-time values are character strings or digital states are not included in the average. If all values are character strings or digital states, Avg returns an error value. Returns an error if the array does not consist of same value type

Notes

  • Unit of Measure (UOM) of the arguments is carried over to the result when at least one argument has a defined UOM while others don't. The returned value lacks a UOM if arguments have different UOMs

Example

  • Avg(14, 'att1', 14.5, TagVal('att2', '14-Dec-16'))

    [Find the average of these values: 14, the current value of 'att1', 14.5, and the value for 'att2' at the start of day (12:00am) on Dec 14, 2016]

  • Avg('*', 'y+8h', 'Saturday')

    [Find the average of these time stamps: now, 8:00am yesterday, and start of day (12:00am) last Saturday]

  • Avg('*'-'*-1h', 't+4h'-'y+8h', 'y+2h'-'20')

    [Find the average of these time periods: from 1 hour ago to now, from 8:00am yesterday to 4:00am today, and 2:00am yesterday to the start of day (12:00am) on the 20th of this month]

  • Avg(Variable1)

    Name

    Expression

    Value at Evaluation

    Variable1

    RecordedValues('att1', '*-10m', '*')

    [1, 3, 5, 7, 9]

    Variable 2

    Avg(Variable1)

    5

    [Find the average of values in an array named Variable1]

  • Avg(Data)

    [Return the event-weighted average of values for an array named Data]

  • Avg(Data, "EventWeighted")

    [Return the event-weighted average of values for an array named Data]

  • Avg(Data, "TimeWeighted")

    [Return the time-weighted average of values for an array named Data using the earliest timestamp of the value as the start time and the latest timestamp as the end time]

In This Topic
TitleResults for “How to create a CRG?”Also Available in