A Calculated Tag is a tag that can reference other tags and apply a calculation to the value/s of the source tag/s. The calculation can be simple or complex, with the possibility of applying User Defined Functions.
To create a Calculated Tag, existing tags in the Model View can be dragged onto the Calculator icon in the Flow Zone.
Note what has happened...
Flow has created another tag for you and has named it after the metric name. In the bottom left of this new tag's icon, you can also see that the Retrieval Type is different from the source tag - the icon is an "=" symbol, which represents a calculated tag/measure in Flow.
The tag also has a fault, indicated by the red dot in the top left corner. If you hover your mouse over something that has a fault, Flow will explain what the problem is in a tooltip, in this case, the problem is that the "Calculation has not been validated". This means that you have not confirmed that the calculation expression that is configured has no errors. Of course, you haven't confirmed the expression - you didn't even type it in! Let's see what expression has been configured for you by double-clicking this new tag to open its Editor, and then expand the Retrieval tab ...
By default, the calculation is expression is the source tag multiplied by 1. The unit of measure is also taken from the source tag.
The checkmark in the top right corner of the calculation editor is blue, which indicates that the expression requires validation (this aligns with the fault that we noted in the Model View for this calculated tag). Click the blue checkmark to validate the calculation - this will confirm that the expression you entered can be processed by Flow
By hitting the Refresh Now button in the Chart View, it will update the results of your expression int he data previewer.
In this case, the calculation is simply dividing the source data by a factor of a 1000. What other properties of a source' tag is available to use in your calculation? The Insert menu will list parameters that can be accessed on the source tag.
- Value - The Value of the source tag (TVQ)
- Quality - The OPC quality good retrieved from the Data Source (TVQ)
- String Value - If the Tag is of type String, the String Value will hold the string value of the tag (TVQ)
- Points - this will be an array of TVQ objects if you want to run through the tag values to potentially do a slope calculation. This is used in conjunction with a range transform on a tag. An Example of a Slope Calculation can be seen below:
(MyMeasure.Points[MyMeasure.Points.Length -2].Value
- MyMeasure.Value) /
(MyMeasure.Points[MyMeasure.Points.Length -2].Timestamp
-MyMeasure.Timestamp).TotalSeconds
- Timestamp - a DateTime of the time the tag changed (TVQ)
- Duration - Time in milliseconds between now and the previous changed value.
- Model Attributes - Model attributes can be used in your calculation expressions. Thes could hold ratios, setpoints, ratings ect. Note. Model attributes are string values. If you have a Model Attribute representing a number, you will need to convert the value first. An Example using a TryParse function is listed below:
Double.TryParse(MyMeasure.ModelAttributes["Rating"].Value, out double value)
? value:0.0
Fault Finding
You can add the original tag to the data previewer as well to see the result of your calculation in relation to the source tag:
This will add the source tag to the chart as well.
If there was more than one source tag to this calculated tag, you would have the option to add any/all of them as pens to the chart. This is very useful when you want to verify that your calculation expression is correct.
Remember, the values that you see in a tag are not being stored in the Flow database; they are being retrieved from the data source and, in the case of a calculated tag, the calculation expression is being applied in real-time and then displayed on the chart view. The advantage of this is that you can combine tags from different data sources that you require for a calculation without using any licensed measures. It is only when you use your tags/calculated tags in a measure that you use a single licensed measure.
At the same time, you can display the values of your tags and calculated tags in Pass-through charts and you can even use the Flow API to read these values from your data sources via Flow.