A key function in creating a realtime datapoint with computation is the previous value function. This function allows you to utilize the last stored value in the datapoint time series, allowing the computation of delta values.
When a realtime datapoint that incorporates the PREVIOUS_VALUE function in a computation is first executed, the initial computed value stored is zero.
Here is simple example of how the datapoint value is stored for each computation for the simple expression. As new JSON payloads arrive, the value from the most recent payload is extracted and becomes the Previous Value, which is then used in the new computation.
Let's consider an example where a gateway device sends fuel level values as payload. From this payload, a fuel level datapoint is created to store the fuel levels. Now, a computed realtime datapoint named 'Fuel Consumed' can be created to log the amount of fuel used at each instance. The expression for this computation will be as below.
The following table shows example payload values along with the computed values stored in the datapoint for this expression.
| Received Value
(from Payload)
| Previous Value | Computed and Stored (Fuel Consumed) |
Payload 1 | 100 | - | - |
Payload 2 | 90 | 100 | 100 - 90 = 10 |
Payload 3 | 75 | 90 | 90 - 75 = 15 |
Payload 4 | 63 | 75 | 75 - 63 = 12 |
Payload 5 | 48 | 63 | 63 - 48 = 15 |
Payload 6 | 33 | 48 | 48 - 11 = 15 |
When visualized using the data explorer, the data will appear as follows.
The violet bar represents the fuel level value (extracted from the payload), and the pink bar represents the fuel consumed value (computed using expression) at defined intervals.