Hi

New day new problem to solve

I want to calculate my energy cost between two points in time. For example 01.01.2021 and 31.12.2021.

This is the query for my enery meter. The data source adds multiple datapoints per minute. So enough data here to work withâ€¦

```
from(bucket: "iobroker")
|> range(start: 2021-01-01, stop: 2021-12-31)
|> filter(fn: (r) => r["_measurement"] == "sonoff__0__Smartmeter__Power_Total_in"
|> filter(fn: (r) => r["_field"] == "value")
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> spread(column: "_value")
```

To simplify things, letâ€™s say this will give me an output of 5000 (kwh)

It would be very easy to just multiply this value with my enery costâ€¦ But unfortunately the price isnâ€™t a constant value

From 01.01.2021 - 01.05.2021 the enery cost per kwh was 0,28â‚¬

And since 01.06.2021 the price was adjusted to 0,41â‚¬

There are only two values to work with:

Also notice the timestamp of the first measurement. It isnâ€™t even in the selected range.

Any idea, how to solve this?