---
title: Introduction to Calculated tags
description: Calculated input is about setting up a calculation expression with one of more tags, like adding the readings from 2 tags together. In the following article, you will get an introduction to Calculated
---

[Skip to content](https://kb.dataintel.dk/introduction-to-calculated-inputs#main-content)

English

Show submenu for translations

[Submit a request](https://kb.dataintel.dk/kb-tickets/new?hsLang=en)

![DIAP-1.png\]](https://kb.dataintel.dk/hs-fs/hubfs/DIAP-1.png?height=41&name=DIAP-1.png)

- [Default HubSpot Blog](https://diap-6547305.hs-sites.com/blog)

Open main navigation

Close main navigation

- [Default HubSpot Blog](https://diap-6547305.hs-sites.com/blog)
- English
  
  Show submenu for translations
- [Submit a request](https://kb.dataintel.dk/kb-tickets/new)
- Go to Data Intelligence A/S

 Go to Data Intelligence A/S

 Hello. How can we help you?

- There are no suggestions because the search field is empty.

1. [Help Center](https://kb.dataintel.dk/?hsLang=en)
2. [Configuration](https://kb.dataintel.dk/configuration?hsLang=en)
3. [Guides](https://kb.dataintel.dk/configuration?hsLang=en#guides)

# Introduction to Calculated tags

### Calculated input Group Logic

Calculated input is about setting up a calculation expression with one of more tags, like adding the readings from 2 tags together. In the following article, you will get an introduction to **Calculated input groups**.

### Accessing the interface

Navigate to "**DIAPs**" and select it.  
![](https://kb.dataintel.dk/hubfs/Knowledge%20Base%20Import/eltronic.zendesk.comhcarticle_attachments360004866080mceclip0.png)

 

Choose the DIAP which you wish to add **Calculated inputs** for:

![](https://kb.dataintel.dk/hubfs/Knowledge%20Base%20Import/eltronic.zendesk.comhcarticle_attachments360004924319mceclip1.png)

 

Choose the "**+ Add calculated input group**" in order to add a group for creating calculated tags. A calculated input group is basically a kind of virtual/software PLC, that can be setup and run inside the DIAP. It is a way for logical grouping a set of tags and it is needed to keep the relation between DIAP, tags' groups and tags.

![](https://kb.dataintel.dk/hubfs/image-png-Nov-15-2021-02-47-53-54-PM.png)

 A pop-up will occur:

- **Name:** The name of the calculated tags group (The virtual/software PLC)
- **Location:** Just enter something here because this isn't used.
- **Description:** A description of the calculated tags group.
- **Scan Rate (ms):** The default scan rate, that will be used when adding a new input into this calculated tags group (This can be overwritten in the tag setting).
- **Stop tag:** This setup is for when the tags in the group shouldn't collect data. Just set it to **No stop tag**, this will stop the tag from collecting data, when its reading is equal to that in the **Stop value**.
- **Stop value:** This value is used to check if the tag shouldn't collect data.
- **Is Active:** Sets the calculated tag group active or inactive. Tags in an inactive active group won't collect data.

![](https://kb.dataintel.dk/hubfs/image-png-Nov-15-2021-02-26-51-91-PM.png)

Once the group has been created, then it can be expanded in order to add new inputs. Click "**Add calculated input**".

![](https://kb.dataintel.dk/hubfs/image-png-Nov-17-2021-07-39-17-21-AM.png)

A **calculated input** is basically a tag, where one defines an expression to it, that will be calculated like a math formula. You must select a **Sensor type**, enter a **Name** for the calculated input:

![](https://kb.dataintel.dk/hubfs/image-png-Nov-15-2021-02-57-31-27-PM.png)

Now you must specify the **expression**, that should be calculated, this expression most likely involves the use of other tags. To add a tag to the expression, click "**Add new tag**":

![](https://kb.dataintel.dk/hubfs/image-png-Nov-15-2021-03-02-16-00-PM.png)

 

Press the button "**+ Add new input**" and select the **PLC** and **tag**.   
![](https://kb.dataintel.dk/hubfs/image-png-Nov-15-2021-03-03-43-16-PM.png)

The added tag can now be seen in a list below:![](https://kb.dataintel.dk/hubfs/image-png-Nov-15-2021-03-06-24-43-PM.png)

Repeat this for each tag needed in the **expression.**

To insert a tag into the **expression**, copy it's **TagId**, into the **expression** input: ![](https://kb.dataintel.dk/hs-fs/hubfs/image-png-Nov-15-2021-03-13-09-40-PM.png?width=655&name=image-png-Nov-15-2021-03-13-09-40-PM.png)

Here is an example of getting the sum of 2 tags, where **Sum tag** returns the sum of tag **Shift 0\<-\>** and **irregular int**:![](https://kb.dataintel.dk/hubfs/image-png-Nov-15-2021-03-15-50-84-PM.png)

The rest of the settings for the calculated input are standard tag settings, which you can read more about here: [Configuration of tags (PLC)](https://kb.dataintel.dk/configuration-of-tags-plc?hsLang=en).  
![](https://kb.dataintel.dk/hubfs/image-png-Nov-15-2021-03-21-17-64-PM.png)

### Basic usage examples

Here are some examples of use, using only three tags:

- t997 - a simple boolean (can hold value 0 or 1).
- t998 - a value between -127 and 128.
- t999 - a simple boolean (can hold value 0 or 1) on another PLC.

![](https://kb.dataintel.dk/hubfs/image-png-Nov-16-2021-02-31-31-73-PM.png)

#### Mathematic:

Tags as shown above where:

```
t997 = 0t998 = -3 t999 = 1
```

Basic:

```
t999 + t997 = 1t997 - t998 = 3t999 / t998 = 1 / -3 = -0.3333~
```

Adding more complexity:

```
t998 * - t999 = 1 * - -3 = 3
```

Adding constants:

```
10 * t998 + t999 = 10 * -3 + 1 = -29
```

Adding parentheses:

```
10 * (t998 + t999) = 10 * (-3 + 1) = -20
```

#### Logic:

Tags as shown above where:

```
t997 = 0t998 = 1t999 = 1
```

Basics:

```
t997 & t998 = t997 and t998 = 0t997 | t998  = t997 or t998  = 1
```

Negation:

```
not t997 = 1not t998 = 0not(t997 & t998)  = 1not(t998 & t999)  = 0not(t997 | t998)  = 0not(t998 | t999)  = 0
```

"**not(A & B)**" acts as a NAND gate:

| INPUT | INPUT | OUTPUT |
| --- | --- | --- |
| **A** | **B** | **A NAND B** |
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |

"**not(A | B)**" acts as a NOR gate:

| INPUT | INPUT | OUTPUT |
| --- | --- | --- |
| **A** | **B** | **A NOR B** |
| 0 | 0 | 1 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 0 |

 

The following logic operators can be used in the expression:

| **Logic operator** | **Description** |
| --- | --- |
| **&** | Logic **and** operator |
| **\|** | Logic **or** operator |
| **not(A & B)** | **NAND** gate |
| **not(A \| B)** | **NOR** gate |

#### Functions:

Tags as shown above where:

```
t997 = 0.7t998 = 1.3t999 = 2.3
```

You can use functions, like **round**, **cos**, **acos**, **floor** and others:

```
round(t999) = round(2.3) = 2  
```

Combining them with math:

```
10 * round(t997) + floor(t998) + 10 = 10 * round(0.7) + floor(1.3) = 10* 1 + 1 = 12 
```

You can only pass 1 parameter to the functions:

1 parameter (OK)

```
round(t997)
```

2 parameters (Not OK)

```
round(t997,2)
```

#### Functions

The following functions can be used in the expression:

| **Function** | **Description** |
| --- | --- |
| **acos** | Returns the arc cosine of a number |
| **asin** | Returns the arc sine of a number |
| **atan** | Returns the arc tangent of a number in radians |
| **atan2** | Returns the arc tangent of y/x in radians |
| **ceil** | Rounds a number up to the nearest integer |
| **cos** | Returns the cosine of a number |
| **cosh** | Returns the hyperbolic cosine of a number |
| **exp** | Returns E raised to the power of x |
| **fabs** | Returns the absolute value of a number |
| **floor** | Rounds a number down to the nearest integer |
| **log** | Returns the natural logarithm of a number, or the logarithm of number to base |
| **log10** | Returns the base-10 logarithm of x |
| **sin** | Returns the sine of a number |
| **sinh** | Returns the hyperbolic sine of a number |
| **sqrt** | Returns the square root of a number |
| **tan** | Returns the tangent of a number |
| **tanh** | Returns the hyperbolic tangent of a number |
| **bool** | Returns the boolean value of the specified object |
| **int** | Returns an integer number |
| **round** | Rounds a number |
| **random** | Returns a random float number between 0 and 1 (Don't take a parameter, like this random()) |
| **omega** | omega(X) - is a function that emulates periodical events and with given rotational speed expressed as a period of 1 rotation per X ms, returns angle that can be used in trigonometric functions as an input parameter. Example: Sine wave = amplitude \* sin(omega(period of wave expressed in ms)) |

**Example of using omega:**

**![](https://kb.dataintel.dk/hubfs/image-png-Dec-01-2021-09-51-39-02-AM.png)**

Then the calculated input will generate a sine wave like this:

![](https://kb.dataintel.dk/hubfs/image-png-Dec-01-2021-10-22-34-65-AM.png)

#### Test expression

The expression is evaluated with python by passing the expression to pythons **eval** function; because of this, you can test your expression in python. You can run python code online here:

[https://www.w3schools.com/python/trypython.asp?filename=demo\_default](https://www.w3schools.com/python/trypython.asp?filename=demo_default)

First import the math library, it has a lot of the math function you can call:![](https://kb.dataintel.dk/hubfs/image-png-Nov-16-2021-09-23-15-07-AM.png)

Now to simulate the tagId, you can declare variables to hold the reading from your tags like this:

![](https://kb.dataintel.dk/hubfs/image-png-Nov-16-2021-09-23-34-50-AM.png)

Next you can see the result of your expression by writing it in a print function like this (round is a built in function and floor is a function in the math library):![](https://kb.dataintel.dk/hubfs/image-png-Nov-16-2021-09-23-53-37-AM.png)

Click the Run button:

![](https://kb.dataintel.dk/hubfs/image-png-Nov-16-2021-09-24-18-20-AM.png)

And see the result of your expression:

![](https://kb.dataintel.dk/hubfs/image-png-Nov-24-2021-08-13-55-19-AM.png)

It properly seems confusing to see the floor function called as **math.floor** on the web site and it called as **floor** in the expression of **calculated input**. It is because the **math** library is included in the **calculated input** and will be searched when a function is called. This means that you don't have to worry about whether the function is builtin or a math library function, you just type the name of the function in the expression.

In python the function are located here:

| **Function** | **Python Location** |
| --- | --- |
| **acos** | **math** library |
| **asin** | **math** library |
| **atan** | **math** library |
| **atan2** | **math** library |
| **ceil** | **math** library |
| **cos** | **math** library |
| **cosh** | **math** library |
| **exp** | **math** library |
| **fabs** | **math** library |
| **floor** | **math** library |
| **log** | **math** library |
| **log10** | **math** library |
| **sin** | **math** library |
| **sinh** | **math** library |
| **sqrt** | **math** library |
| **tan** | **math** library |
| **tanh** | **math** library |
| **bool** | built in function |
| **int** | built in function |
| **round** | built in function |
| **random** | **Random** library |
| **omega** | Not a Python function |

### Underlying lexer and parser rules

```
/* * Parser Rules */evaluate 	: expression EOF	;expression	:  high_op_expression	|  expression (OP_LOWER | BIN_OR_UN) high_op_expression	;high_op_expression	:  temp_expression	|  high_op_expression OP_HIGH temp_expression	;temp_expression	:  brackets	|  function_call 	|  un_op_with_brackets	|  un_op_with_term	|  terminal	;brackets	: '(' expression ')'	;function_call	:  FUNC '(' expression ')'	;un_op_with_brackets	:  (UN_OP | BIN_OR_UN)+ '(' expression ')'	;un_op_with_term	:  (UN_OP | BIN_OR_UN)+ terminal	;terminal	:  NUMBER	|  BOOLEAN	|  TAG 	;/* * Lexer Rules */OP_HIGH	:  'and'	|  '&'	|  '*'	|  '/'	|  '^'	;OP_LOWER	:  'or'	|  '+'	|  '|'	;BIN_OR_UN	:  '-'	;UN_OP	:  'not' 	|  '~'	;TAG	:  [tT][0-9]+	;NUMBER	:   '0' ([xX] [0-9a-fA-F]+         ([lL]  | [eE] [+-]? [0-9]+)?	|        [oO] [0-7]+                [lL]?	|        [bB] [01]+                 [lL]?)	| ([0-9]+ '.' [0-9]* | '.' [0-9]+)         ([eE] [+-]? [0-9]+)?       [jJ]?	|  [0-9]+                          ([lL]  | [eE] [+-]? [0-9]+ [jJ]? | [jJ])?	;BOOLEAN	:  'True'	|  'False'	;FUNC	:  'acos'| 'asin'| 'atan'| 'atan2'| 'ceil'| 'cos'	|  'cosh'| 'exp'| 'fabs'| 'floor'| 'log'| 'log10'        |  'sin'| 'sinh'| 'sqrt'| 'tan'| 'tanh'|'bool'	|  'int'| 'round'| 'random'| 'omega'	|  	;WHITESPACE          	:  (' '|'\t')+ -> skip ;
```

### Recommended setup.

Combining the readings from several tags, can give behavior that seems strange, to avoid this you should set the **scan rate** ofthe calculated input and the tags used in the expression of the calculated input to the same value and the tags should come from the same **PLC**.

- **Scan rate** should be the same for calculated input and tags used by it.
- The tags used by the calculated input, should come from the same **PLC**.

### Why the scan rate should be the same for calculated input and tags used by it

The reason why the scan rate should be the same, is because the calculated input has to use simultaneous values from the tags else the results can be incorrect. Imagine that you have a tag measuring current and other one measuring voltage. Now you want to calculate the power from these tags, you think "Simple, I just multiple them" after all the power formula is:

```
P(t) = U(t)* I(t)
```

And your current and voltage are waves:

 ![](https://kb.dataintel.dk/hubfs/image-png-Nov-17-2021-01-04-39-02-PM.png)

And you scan your Current every 2 seconds and Voltage every 3 seconds:

![](https://kb.dataintel.dk/hs-fs/hubfs/image-png-Nov-23-2021-07-35-55-93-AM.png?width=678&name=image-png-Nov-23-2021-07-35-55-93-AM.png)

Now image that we don't care when the scan happens and take values that are not simultaneous, then the question comes, which values do we pair with each other:

![](https://kb.dataintel.dk/hs-fs/hubfs/image-png-Nov-17-2021-01-23-18-46-PM.png?width=308&name=image-png-Nov-17-2021-01-23-18-46-PM.png)

And even if we made a choice here, no matter which choice we take, the result would be wrong, because it the Current's value isn't neither of the choices, when we use a Voltage reading(This is also true, if we try paring from Current to Voltage):

![](https://kb.dataintel.dk/hs-fs/hubfs/image-png-Nov-17-2021-01-42-16-32-PM.png?width=568&name=image-png-Nov-17-2021-01-42-16-32-PM.png)

And lastly, we must also take into account, when the calculated input is set to calculate the result via its scan rate, this also has to match the values from the tags. For example say that you set the scan rate of the calculated input to 5 seconds:

![](https://kb.dataintel.dk/hs-fs/hubfs/image-png-Nov-17-2021-01-56-27-80-PM.png?width=534&name=image-png-Nov-17-2021-01-56-27-80-PM.png)

As you can see above, the calculated input toggles between having the Current and Voltage and therefore it isn't possible for it to make the calculation and as just explain before, we can't pair values that are not simultaneous.

The way we handle different scan rate on tags and calculated input, is to use the lowest common denominator for all of the scan rates. In the example before this would mean, that you would first get a result after 30 seconds, because that is the lowest common denominator between 2, 3 and 5. So if you want the results fast, when you have to think about setting their scan rate to the same or to something, where the common denominator is low enough for you.

### Why the tags used by the calculated input, should come from the same PLC

The reason why the tags used by the calculated input, should come from the same PLC, is because the clocks should be synchronized between the tags. Lets look at the Current and Voltage example, say that the Current tag is measured from PLC **P1** and Voltage tag is measured from PLC **P2**:

![](https://kb.dataintel.dk/hubfs/image-png-Nov-23-2021-09-42-39-15-AM.png)

And image, that the clock on PLC P1 is 1 second late:![](https://kb.dataintel.dk/hubfs/image-png-Nov-23-2021-09-49-09-37-AM.png)

This can cause simultaneous values to appear not simultaneous, when the tags are read:

![](https://kb.dataintel.dk/hubfs/image-png-Nov-23-2021-10-00-04-24-AM.png)

and not simultaneous values appear simultaneous, when the tags are read:

![](https://kb.dataintel.dk/hubfs/image-png-Nov-23-2021-10-03-41-41-AM.png)

### Tolerance on simultaneous values

Because clocks are not perfect synchronized with each other in the DIAP and PLCs, we have added a tolerance for when values between tags and calculated input are seen as simultaneous. This tolerance is 100 milliseconds, if tag's values are within 100 milliseconds of when they are read by the calculated input, then they are seen as simultaneous values and used by the calculated input:

![](https://kb.dataintel.dk/hubfs/image-png-Dec-01-2021-09-30-34-55-AM.png)

- [DIAP Gateway](https://kb.dataintel.dk/diap-gateway?hsLang=en#main-content)

    - [Getting Started](https://kb.dataintel.dk/diap-gateway?hsLang=en#getting-started)
    - [Troubleshooting](https://kb.dataintel.dk/diap-gateway?hsLang=en#troubleshooting)
    - [Known issues/limitations](https://kb.dataintel.dk/diap-gateway?hsLang=en#known-issues-limitations)
- [General](https://kb.dataintel.dk/general?hsLang=en#main-content)

    - [FAQ](https://kb.dataintel.dk/general?hsLang=en#faq)
- [Configuration](https://kb.dataintel.dk/configuration?hsLang=en#main-content)

    - [FAQ](https://kb.dataintel.dk/configuration?hsLang=en#faq)
    - [Troubleshooting](https://kb.dataintel.dk/configuration?hsLang=en#troubleshooting)
    - [Guides](https://kb.dataintel.dk/configuration?hsLang=en#guides)
    - [Protocols](https://kb.dataintel.dk/configuration?hsLang=en#protocols)
- [Live/Real time site](https://kb.dataintel.dk/live-real-time-site?hsLang=en#main-content)

    - [Getting Started](https://kb.dataintel.dk/live-real-time-site?hsLang=en#getting-started)
    - [FAQ](https://kb.dataintel.dk/live-real-time-site?hsLang=en#faq)
    - [Guide](https://kb.dataintel.dk/live-real-time-site?hsLang=en#guide)
    - [Features](https://kb.dataintel.dk/live-real-time-site?hsLang=en#features)
- [OEE site](https://kb.dataintel.dk/oee-site?hsLang=en#main-content)

    - [Getting Started](https://kb.dataintel.dk/oee-site?hsLang=en#getting-started)
    - [FAQ](https://kb.dataintel.dk/oee-site?hsLang=en#faq)
    - [Guides](https://kb.dataintel.dk/oee-site?hsLang=en#guides)
    - [Configuration](https://kb.dataintel.dk/oee-site?hsLang=en#configuration)
- [Remote Access](https://kb.dataintel.dk/remote-access?hsLang=en#main-content)

    - [Getting Started](https://kb.dataintel.dk/remote-access?hsLang=en#getting-started)
    - [FAQ](https://kb.dataintel.dk/remote-access?hsLang=en#faq)
    - [Guides](https://kb.dataintel.dk/remote-access?hsLang=en#guides)
- [API](https://kb.dataintel.dk/api?hsLang=en#main-content)

    - [API](https://kb.dataintel.dk/api?hsLang=en#api)
- [Release information](https://kb.dataintel.dk/release-information?hsLang=en#main-content)

    - [DIAP Release Notes](https://kb.dataintel.dk/release-information?hsLang=en#diap-release-notes)
    - [Live/Real time site](https://kb.dataintel.dk/release-information?hsLang=en#live-real-time-site)
    - [OEE site](https://kb.dataintel.dk/release-information?hsLang=en#oee-site)
    - [Management site](https://kb.dataintel.dk/release-information?hsLang=en#management-site)
    - [DIAP Gateway](https://kb.dataintel.dk/release-information?hsLang=en#diap-gateway)

- [Default HubSpot Blog](https://diap-6547305.hs-sites.com/blog)

[![Chill listening crop-3](https://kb.dataintel.dk/hs-fs/hubfs/Sk%C3%A6rmbillede%202021-05-04%20kl.%2017.46.04.png?width=221&height=26&name=Sk%C3%A6rmbillede%202021-05-04%20kl.%2017.46.04.png "Chill listening crop-3")](https://diap.hubspotpagebuilder.com/-temporary-slug-5b226bcb-69c8-45c1-82ff-e060e2d4037d?hsLang=en)

Copyright © 2026, Data Intelligence A/S