Median (Tag-based PE function)
- Last UpdatedOct 04, 2024
- 1 minute read
- PI System
- PI Server 2018
- PI Server
Return the median (middle) value for a set of three or more values.
Syntax
Median(x1, x2, x3, [... xn])
Arguments
x1, x2, x3, [... xn]
All arguments must be the same type. Enter at least three arguments, all of the same data type (integers and real numbers, times, or time periods).
Returns
The median value of the input arguments. If the number of arguments is even, the average of the two middle values is returned.
Exceptions
Arguments whose run-time values are digital states are ignored. The function must have greater than two arguments that evaluate to non-digital states; otherwise, Median returns an error value.
Notes
Median allows for mixed integer and real data types. Median follows the data type of the first argument. Hence if the first argument is a point that evaluates to an integer then all the other entries are converted to integers by rounding.
Example
-
To find the median of these timestamps: now, 12:00am yesterday, and 12:00am last Saturday:
Median('*', 'y', 'Saturday')
-
To find the median of these values: 14, the current value of tag1, 14.5, and the value for tag2 at midnight on Dec 14, 2016:
Median(14, 'tag1', 14.5, TagVal('tag2','14-Dec-16'))
-
To find the median of these time durations: from 1 hour ago to now, from 12:00am yesterday to 12:00am today, and the total time tag1 was equal to 50 between 12:00am yesterday and 12:00am today:
Median('*'-'*-1h', 't'-'y', TimeEq('tag1', 'y', 't',50))