Multiply two irregular series

Hi,

After reading a lot of forums I still can’t figure this out…

I have two irregular series. The first one reads data from my power cabinet ([kW], one sample every ~2nd second). The second one is the price ([local currency / kWh]), 2-3 samples every hour.

My intention is to calulate the total cost / price for a given time range (multiplying consumption and price, and probably integrate under that curve/graph?).

from(bucket: "amsdata")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "consumption")
  |> filter(fn: (r) => r["_field"] == "kW")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

from(bucket: "amsdata")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "spotprice")
  |> filter(fn: (r) => r["_field"] == "price")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Power consumption and price
image

I will appreciate your help :slight_smile:

You are using aggregateWindow with a fixed windowPeriod for both queries. That’s great because it means that you will have synchronized times.

You can join the two tables on the time column, and then map to add a calculated field ($$$ / kWh). See Join data in InfluxDB with Flux | InfluxDB Cloud Documentation for the documentation and examples.

1 Like