# Integration Toolkit Solutions Wiki

**URL:** <https://forum.inductiveautomation.com/t/integration-toolkit-solutions-wiki/105080>\
**Category:** 3rd Party Modules\
**Tags:** scripting, ignition81\
**Created:** [April 14, 2025, 9:02pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-solutions-wiki/105080 "2025-04-14T21:02:36Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [April 16, 2025, 11:58pm UTC](https://forum.inductiveautomation.com/t/integration-toolkit-solutions-wiki/105080/10 "2025-04-16T23:58:29Z")

</div>

## Incremental readings from totalising meter using asMap() and lag()

Useful for extracting the difference in periodic meter readings.

> **Sample dataset**
>
> ```python
> "#NAMES"
> "t_stamp","reading"
> "#TYPES"
> "date","I"
> "#ROWS","6"
> "2025-04-17 00:00:00.000","5"
> "2025-04-17 01:00:00.000","7"
> "2025-04-17 02:00:00.000","11"
> "2025-04-17 03:00:00.000","17"
> "2025-04-17 04:00:00.000","25"
> "2025-04-17 05:00:00.000","35"
> 
> ```
> 
> or paste the JSON below onto a component's `custom.data`.
> 
> ```python
> [
> {"t_stamp": 1744844400000, "reading": 5 },
> {"t_stamp": 1744848000000, "reading": 7},
> {"t_stamp": 1744851600000, "reading": 11},
> {"t_stamp": 1744855200000, "reading": 17},
> {"t_stamp": 1744858800000, "reading": 25},
> {"t_stamp": 1744862400000, "reading": 35}
> ]
> 
> ```

> **Output**
>
> ```python
> [
> {"t_stamp":1744844400000,"reading": null},
> {"t_stamp":1744848000000,"reading": 2},
> {"t_stamp":1744851600000,"reading": 4},
> {"t_stamp":1744855200000,"reading": 6},
> {"t_stamp":1744858800000,"reading": 8},
> {"t_stamp":1744862400000,"reading": 10}
> ]
> 
> ```

> **Expression binding**
>
> e.g., on Perspective custom property:
> 
> ```python
> forEach(
> {this.custom.data},
> asMap(
> 't_stamp', it()['t_stamp'], 
> 'Increment', it()['reading'] - lag()['reading']
> )
> )
> 
> ```

> **Functions employed**
>
> - [forEach()](https://www.automation-pros.com/toolkit/doc/iteration.html#foreach) loops through the items in the source.
> - [asMap()](https://www.automation-pros.com/toolkit/doc/iteration.html#asmap) produce a Java Map with string keys.
> - [it()](https://www.automation-pros.com/toolkit/doc/iteration.html#it) retrieves the loop value for the **it** erator.
> - [lag()](https://www.automation-pros.com/toolkit/doc/iteration.html#lag) retrieves the **previous** loop value for the iterator. It returns _null_ for the first pass and so the incremental reading will be null for the first interval. (The _null_ in calculation seems to be neatly handled by the asMap() function which returns a _null_.)

---

_[View the full topic](https://forum.inductiveautomation.com/t/integration-toolkit-solutions-wiki/105080)._
