---
title: Creating a calculation
slug: how-tos/5ko0-creating-a-calculation
createdAt: 2025-09-05T12:07:12.279Z
---

Creating a calculation is similar to [creating a measurement](docId\:u5-07YlMs2jiX9Kz-m-lB).

1. Configure the basic measurement properties
2. Choose a calculation type
3. Specify the calculation settings, which depend on the calculation type:
   - Raw calculation
   - Sampled calculation
   - Simulated calculation
4. Setup the calculation script

:::hint{type="info"}
To reference data references in the script, use its alias (here `_A`) instead of the reference’s name.
:::

## Calculation lifecycle

A calculation can either be Paused or Active.

### Paused

When clicking the pause button on an active calculation, the calculation will stop its operation until it is resumed.
A paused calculation will not output any new time series data.

### Active

To resume the calculation, click the `Resume` button. When resuming a calculation, processing will restart at the beginning of the next interval.
Consequently, no new time series data will have been processed while the calculation was paused!

## Calculation context

Every calculation keeps a stateful context, which retains the last result and timestamp of the calculation along with other information and the local context (see below for a full list).

:::hint{type="info"}
When the type of a calculation is changed  (e.g. from sampled to raw), its context is automatically reset.
:::

### Editing the calculation context

The context of a calculation can only be changed if the calculation is paused.

The calculation context will always contain the Context itself under the `Context` key. The local context is at the top level.
The calculation context contains the following fields:

- `<local context field 1>`
- `<local context field 2>`
- `Context`
  - `PreviousResult`: the last result of the calculation
    - `Value`: The value returned by the last run of the calculation
    - `Tags`: A map of tags set which can be set in the script
    - `Status`: The status set in the script, will only be visible if set inside the script
  - `IntervalMs`: The interval at which the calculation is executed
  - `OffsetMs`: The offset at which the calculation is executed
  - `Timestamp`: The timestamp of the current calculation
  - `PreviousTimestamp`: The timestamp of the previous calculation
  - `PreviousInput`: The previous value of the input data reference(s)
    - Input data reference alias: Example \_A
      - Tags: The time series tags of the input data reference, example “status”
      - Datatype: The datatype of the input data reference
      - Data reference: The name of the input data reference
      - Timestamp: The timestamp of the input data reference
      - Value: The value of the input data reference

You can edit/add anything inside the context.

The following variable types are available:

- string
- int
- float
- bool
- time
- map
- array

Look at some examples on how to use the calculation context [here](docId:9vedQPMTtHzwUy1cLKaVh).
