# Calculated tags

Calculated tags have a formula that uses the values of one or more existing tags to compute the result. Both live and historical calculations are provided. For the calculation of historical values, data records of all parameters must be available.

## Create calculated tag

In tree, a new calculated tag can be created in the **Calculated values** node via the icon.

First, a data type (numeric or logical) must be selected. Note that the data type cannot be changed after it has been saved for the first time.

Then the formula can be entered. Tags can be added via drag & drop or by entering the name.
Tip: Via `Ctrl+space`

a selection of all available tags and functions appears.

## Formula operators

In addition to the standard mathematical functions, such as addition (`+`

), subtraction (`-`

),
multiplication (`*`

) and division (`/`

), the following operations are offered:

`Pow("num", "exp")` |
Returns a specified number `num` raised to the specified power `exp` . |

`Sqrt("num")` |
Returns the square root of a specified number `num` . |

`Abs("num")` |
Returns the absolute value of a specified number `num` . |

`If("exp","t","f")` |
Returns `t` if the conditions `exp` is true, otherwise returns `f` . |

`Min("num", "num")` |
Returns the smaller of two numbers. |

`Max("num", "num")` |
Returns the larger of two specified numbers. |

`Log("num", "base")` |
Returns the logarithm of a specified number `num` in a specified base `base` . |

`Cos("num")` |
Returns the cosine of the specified angle `num` . |

`Sin("num")` |
Returns the sine of the specified angle `num` . |

`Tan("num")` |
Returns the tangent of the specified angle `num` . |

Logical conditions can be used in `AND`

/`OR`

notation as well as in `&&`

/`||`

notation.

Comparison operators are `<`

, `>`

, as well as `<=`

and `>=`

.

The operator for modulo is `%`

.

Constant numbers are specified in international format, i.e. with a dot (`.`

) as decimal separator.

## Historical analysis

The historical analysis of a calculated tags only works if the history of all parameters exists. For calculation, all time series are loaded and the formula is applied to each time/value combination.

## Special case: Logical tags

If a logical tag is used in a numerical formula, the operating hours are used. Example: `EnginOn * 1.5`

.
With this simple formula the energy of a machine can be calculated. With this simple formula the energy of a machine can be calculated.
The number of hours the machine is running, is multiplied by the power (here 1.5kW).
When calculating the live value, either 0kW (`0 * 1.5`

if `EnginOn=false`

) or 1.5kW (`1 * 1.5`

if `EnginOn=true`

) is returned.

## Counter and consumption values

When using counter and consumption tags, power/throughput is always used (see counter concept).