Difference of min and max over $__interval

Hello,

I have the value of my Electricity counter (kWh) in a series.
Now, I’d like to show in a pie-chart the power consumed over $__interval.

With a fixed time of -say- a day, this query works:
SELECT max(“value”)-min(“value”) FROM “eg.Wohnzimmer.Hauptlicht.Verbrauch” WHERE $timeFilter GROUP BY time(1d) fill(previous)

But when using
SELECT max(“value”)-min(“value”) FROM “eg.Wohnzimmer.Hauptlicht.Verbrauch” WHERE $timeFilter GROUP BY time($__interval) fill(previous)

I get a way to small value (0.67 vs expected ~5). When formating as a timeseries, I can see that my query does not create one value, but many values (differences)

So, I seem to have differences now between each two datapoints in the interval. I try to sum them up with

SELECT cumulative_sum(max("value")-min("value"))  FROM "eg.Wohnzimmer.Hauptlicht.Verbrauch" WHERE $timeFilter GROUP BY time($__interval) fill(previous)

(I tried sum as well)
But that gives me “No data”

So, finally I tried:

SELECT max("value") - min("value") FROM "eg.Wohnzimmer.Hauptlicht.Verbrauch" WHERE $timeFilter

It gives me a value of 4.5

Is this what I want?

Greetings,
Hendrik

IMHO you will want to use DERIVARE function which will calculate rate from the counter. Search this forum or internet - it seems to be FAQ.

Hello,

the derivative would have the Unit kW. That is the Power. I want the work (kWh).
Thus, I do not need a derivative or an Integral (latter I would need if I had the Power and would want the Work, and that is what I always find when searching).

I just need the difference of my counter at the beginning of the interval and the end of the interval.

Regards,
Hendrik

Hi, Maybe this could help you

Why not SPREAD()?

SPREAD()

Returns the difference between the minimum and maximum field values.

2 Likes

I had the same issue as the topicstarter, SPREAD solved all of my problems!

Anyone any luck with getting a spread based on the interval?

ref Problem with influxdb and energy-monitor - #9 by patvdleer

1 Like

Nice! Exactly the answer I was looking for.