# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.monokot.io/scripts/programming-examples/how-to-calculate-arithmetic-mean.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
