Calculation based on date of each dataset

HI All,

I’d like to do some calculations based on the date of the respective dataset.

I have a dataset which let’s say:

2024-01-02T00:00:00.000Z / 5017.609999999404
2024-01-03T00:00:00.000Z / 21893.759999999776
2024-01-04T00:00:00.000Z / 19366.27999999933

Now I need to do some calculation based on the date, meaning that on Jan 2nd e.g. plus 2, Jan 3rd plus 5, and so on. I have a formula/table which calculates what to add based on the date.

Background: The daily values are the cumulated production of my PV panels. I have as well the predication based on the simulation software as daily average per month. Now I would like to have for each day the cumulated difference between the actual production and the prediction for the current year until the current day.

Thanks!
Oliver

You will need to use map() to perform this calculation for the given date, something like this:

from(bucket: "your_bucket")
  |> range(start: 2024-01-01T00:00:00Z, stop: 2024-01-05T00:00:00Z)
  |> filter(fn: (r) => r._measurement == "your_measurement")
  |> map(fn: (r) => ({
      r with 
      _value: if r._time == 2024-01-02T00:00:00Z then r._value + 2
             else if r._time == 2024-01-03T00:00:00Z then r._value + 5
             else if r._time == 2024-01-04T00:00:00Z then r._value + 3
             else r._value
    }))

Ah, thanks, r._time was what I was looking for. With that I can do my calculation as you suggested.

1 Like