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

AF SDK Reference

AFCalculation.PercentTrue Method

  • Last UpdatedNov 18, 2025
  • 3 minute read
AFCalculation.PercentTrue Method
This method evaluates the passed boolean expression over the passed time range. The passed time range is first divided into a number of calculation intervals. The method then computes the percentage of time the passed expression evaluates to true over each of the periods.

Namespace:  OSIsoft.AF.Data
Assembly:  OSIsoft.AFSDK (in OSIsoft.AFSDK.dll) Version: 3.1.1.1182

Syntax

public static AFValues PercentTrue(
	Object target,
	string expression,
	AFTimeRange timeRange,
	AFTimeSpan calculationInterval,
	AFTimeSpan minimumSampleInterval,
	AFTimestampCalculation timeType,
	out AFValues percentGood
)
Public Shared Function PercentTrue ( 
	target As Object,
	expression As String,
	timeRange As AFTimeRange,
	calculationInterval As AFTimeSpan,
	minimumSampleInterval As AFTimeSpan,
	timeType As AFTimestampCalculation,
	<OutAttribute> ByRef percentGood As AFValues
) As AFValues

Dim target As Object
Dim expression As String
Dim timeRange As AFTimeRange
Dim calculationInterval As AFTimeSpan
Dim minimumSampleInterval As AFTimeSpan
Dim timeType As AFTimestampCalculation
Dim percentGood As AFValues
Dim returnValue As AFValues

returnValue = AFCalculation.PercentTrue(target, 
	expression, timeRange, calculationInterval, 
	minimumSampleInterval, timeType, 
	percentGood)
public:
static AFValues^ PercentTrue(
	Object^ target, 
	String^ expression, 
	AFTimeRange timeRange, 
	AFTimeSpan calculationInterval, 
	AFTimeSpan minimumSampleInterval, 
	AFTimestampCalculation timeType, 
	[OutAttribute] AFValues^% percentGood
)
static member PercentTrue : 
        target : Object * 
        expression : string * 
        timeRange : AFTimeRange * 
        calculationInterval : AFTimeSpan * 
        minimumSampleInterval : AFTimeSpan * 
        timeType : AFTimestampCalculation * 
        percentGood : AFValues byref -> AFValues 

Parameters

target
Type: SystemObject
The target can either be a PIServer, an AFDatabase, or any derived objects of AFBaseElement. References to attributes or points within the expression are based on the target.
expression
Type: SystemString
A string containing the boolean expression to be evaluated. The syntax for the expression generally follows the Performance Equation syntax as described in the PI Data Archive documentation, with the exception that expressions which target elements use attribute names in place of tag names in the equation.
timeRange
Type: OSIsoft.AF.TimeAFTimeRange
The bounding time for the evaluation period.
calculationInterval
Type: OSIsoft.AF.TimeAFTimeSpan
The length of the calculation interval. A value will be returned for each interval within the specified time range.
minimumSampleInterval
Type: OSIsoft.AF.TimeAFTimeSpan
Specifies the minimum sample time within each interval to evaluate the expression at. A smaller sample time will provide a more accurate answer at the cost of longer execution time and heavier PI Data Archive load.
timeType
Type: OSIsoft.AF.DataAFTimestampCalculation
A flag indicating what how to calculate a timestamp for each interval.
percentGood
Type: OSIsoft.AF.AssetAFValues
Out parameter indicating the percent good of each calculation interval value.

Return Value

Type: AFValues
Returns an AFValues collection with each value containing the percentage of time the expression was true over each calculation interval.

Remarks

The caller can also control how often the expression is evaluated during the computation of the Percent True results with the MinSampleInterval argument. The server will limit the MinSampleInterval to between 1/100 and 1/10000 of the calculation period. This flexibility allows the user to manage the trade-off between accuracy and execution time. Higher accuracy typically imposes a heavier load on the server. In the extreme cases, this may impact other applications from accessing the server.

Calculations are limited to Attributes or PI Points which originate from a single PI Data Archive. Attributes which resolve to a static value (no data reference configured), are also acceptable.

Version Information

AFSDK


See Also

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