> For the complete documentation index, see [llms.txt](https://docs.monokot.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.monokot.io/scripts/programming-examples/how-to-calculate-arithmetic-mean.md).

# How to: Calculate Arithmetic Mean

The guide demonstrates how to create an expression that calculates the arithmetic mean between two tags. Before starting, create a Modbus device and two numeric tags named *source\_tag1* and *source\_tag2* respectively.

Open Monokot Server Administrator and double-click *Scripts* on the *Server Explorer* pane. Click *New Expression* and set the name *Mean* for the expression that appears. Insert the following code into the expression code editor:

```javascript
// Getting the value of the first tag
var tag1 = context.data['tag1_trig'].state.value;

// Getting the value of the second tag
var tag2 = context.data['tag2_trig'].state.value;

return (tag1 + tag2) / 2;
```

Press *Ctrl + Enter* to apply the change in the code editor.

Go to the *Triggers* tab and click *Add Data...*. Select the tag created earlier (*source\_tag1*) as the data source for the trigger. Enter the name (key) *tag1\_trig* for the trigger. In the same way, create a data trigger for the second tag.

![](/files/qxE89KEwz7WPBTMQqrHp)

In order for the changes to take effect on the server, click the Sync button. Now, each time one of the tags is updated, the expression will be evaluated. You can see the result of the expression in the *Go Online* mode or read it as an OPC UA variable.

![](/files/rd47UJRw0ujQ95jUNVkE)
