Calculate the difference with a twist

I have an Influxdb database being fed meter values (power, rain) and was intending to use NodeRed to create a difference and feed that into Influxdb. It appears Influxdb can possibly do this directly with a task based on this nearly identical question/answer:

But, the difference is that in my case, the meter will reset when it reaches a maximum (depending on the meter/sensor). What I was wondering is if there is a way to accomplish this in Influx or if I need to process this in another tool and save the results.

In the image I’ve created an example where the meter resets at 30 units. I want to create the 3rd column from the 1st column.

In the end, I only really need the difference stored, so if it’s better to process the incoming data into a delta and not store the raw data, that answer is also reasonable. I am early in this process, so I can change direction. Learning many tools at once is a bit chaotic so I’m trying to determine the process right now more than anything.

I ended up just generating a NR flow that would determine the delta and writing that to Influxdb instead of the raw value. I would have preferred using the raw value since it would keep me from losing data should the system go down for a period of time (I think), but it works.

Hello @bkenobi,
You could do this with flux.
I’m still a little confused by your example because the values in your difference column don’t equal the difference between the sensor and sensor sum. I think perhaps an example with less regular values would make your problem a little bit easier for me to understand and help you.

Are you looking to perform a differencing to remove trend for each period so you can correctly calculate the difference once trend has been removed? If so, you might be interested in applying the timeshift() function to output the adjusted sensor sum. Then you can difference like in the example shown above. flux/ at master · influxdata/flux · GitHub

Or you could potentially use the execd processor plugin or the starlark plugin to handle this type of workload.