Total Consumption summed up Last 7 days (not working)

I’m relatively new to Influx/Grafana and have been sitting for 2 days now with a problem that I just can’t get on with.
It should be relatively simple, but somehow I do not get it.
I have an electricity meter reading, per “Bar gauge” I would like to display the consumption of the last 7 days (total consumption in 7 days).
If I look at the data per:

|> aggregateWindow(every: 1d, fn: last, timeSrc: "_start", offset: 4d)
|> difference()

then the data is correct.
But as soon as I enter 7d, only the consumption of today is displayed.
I understand that 7d = 1w and Influx/aggregatewindow is group by the Unix epoch week.
But how can i solve that.

import "timezone
option location = timezone.location(name: "Europe/Berlin")

from(bucket: "data")
  |> range(start: -14d, stop: now())
  |> filter(fn: (r) => r["_measurement"] == "Kühlschrank.ENERGY_Total")
  |> filter(fn: (r) => r["_field"] == "value")
  |> aggregateWindow(every: 7d, fn: last, timeSrc: "_start", offset: 4d)
  |> difference()
  |> yield(name: "last")

My expectation was to see the consumption summed up (Last 7 days) 11.10.2022 0:00 - 17.10.2022 now()
So 4,144 kWh

Find a Solution:

data = from(bucket: "iobroker") 
|> range(start: -7d) 
|> filter(fn: (r) 
  => r["_measurement"] == "Kühlschrank.ENERGY_Total")
|> filter(fn: (r) => r["_field"] == "value")
min = data 
|> min() 
|> set(key: "_field", value: "delta")
max = data 
|> max() 
|> set(key: "_field", value: "delta")
union(tables: [min, max])
|> difference()
1 Like

Thank you for sharing your solution!
This might also be related: