Calculation syntax
- Last UpdatedJan 25, 2024
- 2 minute read
Writing a calculation expression is similar to writing an expression in arithmetic. You can use any of the standard arithmetic operators (such as +, -, and *) in an expression.
As with arithmetic expressions, the building blocks of a calculation expression are operands and operators. Operators act on operands. A basic expression takes the form: as shown in the following table:
|
Operand |
Operator |
Operand |
Resulting expression |
|---|---|---|---|
|
'TagA' |
+ |
'TagB' |
TagA plus the value of TagB |
|
3 |
- |
'TagC' |
3 minus the value of TagC |
|
7 |
* |
|
7 times the square root of TagD |
You can construct more complex expressions, just as you can in arithmetic. Operations are performed in the same order as they would be performed in a mathematical expression.
Use parentheses to group expressions that you want to evaluate first.
The following example evaluates as the sum of the values of 'TagA' and 'TagB', divided by the difference of 3 minus 'TagC':
('TagA' + 'TagB')/(3 - 'TagC')
This next example is TagA divided by the sum of TagA and TagB:
'TagA'/('TagA' + 'TagB')
More complex expressions for tag-based calculations are also possible. For additional details, see Performance equations (PE) syntax and functions reference in the PI Server documentation.
For asset-based calculations, you can drag and drop AF attributes into the expression editor in the Calculations window. You can drag and drop an asset into the window to set the asset context, but this does not change the expression. Attributes must be from the same database.
If you drag an attribute into a calculation that does not have an asset context, the asset context is set to the element that contains the first attribute. If asset context is already set, an attribute at or below the current context's level is converted to a relative path. Attributes at the same or higher hierarchy level are shown as paths relative to the root of the AF database.
Examples:
AttributeA is dragged into the editor and the asset context is set to Element1. If AttributeB is from Element1, then the syntax will look like:
('AttributeA' + 'AttributeB')/(3 - 'AttributeA')
If AttributeB is from another element in the AF hierarchy, a partial path is included in the syntax:
('AttributeA' + ‘\Grandparent1\Parent1\Element2|AttributeB’/(3 - 'AttributeA')
More complex expressions for asset-based calculations are also possible. For additional details, see Expression functions reference in the PI Server documentation. Expressions that require a specified time interval are not supported.