# Logic & Calculations

In some cases you need to perform data conversions or apply logic to the current data values coming from your server before you apply alarm conditions and notification.

TopView contains internal calculation engines for data manipulation and logic execution. From unit conversions and time-based aggregates to custom-written logic functions, “TopView Operations” and “TopView Logic Functions” provide powerful and efficient calculation and scripting functions.

Examples:

• Perform calculations, logic and mathematical operations on a monitored tag’s value
• Create custom functions to execute advanced logic and arithmetic involving one or more tag values
• Evaluate PI Expressions using PI Performance Equation syntax (TopView PI)
• Count the number of alarms occurring for another tag/row/group over a time period
• Count the number of active alarms in a tag/row/group

## Basic: TopView Operations

TopView’s data sources provide data values that can be monitored for abnormal values and/or behavior.

TopView Operations are built-in mathematical functions and logic that allow the user to manipulate retrieved data values, or create new summary data values, through a set of built-in mathematical functions and logic. The operation result can then be monitored in the same manner as a raw data value.

Supported Operations include

• Alarm counts (current) and totals (over time)
• Add, subtract, multiply, divide, and delta between current tag and a number or second tag
• Time-based average, min, max, range, rate-of-change, standard deviation
• Square root and log of the current tag
• String search (for string/character tag values)
• Execution of PI Expressions

## Advanced: TopView Logic Functions (Tag Expressions)

TopView Logic Functions allow users to perform more advanced logic, operations, and calculations involving one or more inputs (e.g. tag values).

The return value from each Logic Function can be monitored in the same manner as raw data values, allowing the user to apply alarm conditions and notification to the function results.

Logic Functions support the Visual Basic.Net language including variables, if…then…else, arithmetic, and math functions. Each function can be written once yet implemented multiple times for different input lists.

Example:
A tag exists for 3 different flows, one per flow meter. The user would like to create an alarm condition for the total flow (all 3 meters). If the total flow is < 1, set the total flow value to 0.

Function: TotalFlow
Inputs: 3 tag values: Flow1, Flow2, Flow3

Function logic: (result can be monitored by TopView)

`If (flow1 + flow2 + flow3 < 1) then`
`return 0`
`Else`
`return (flow1 + flow2 + flow3)`
`End If`

TopView Logic Functions (11 mins)

We suggest watching in full screen mode (use icon in lower right corner)