Periodic data transformation: fn: last & usePrevious

Good day

I need to implement the following transformation of time series data:

  • time 12:35 value 10
  • time 13:20 value 20

Becomes =>

  • time 12:45 value 10
  • time 13:00 value 10
  • time 13:15 value 10
  • time 13:30 value 20
  • time 13:45 value 20
  • time 14:00 value 20

In other words, values at regular 15-minute time intervals get filled with the latest value which appeared before… I wonder if this is possible using InfluxDB 2 query language.

I tried using the following:

  |> aggregateWindow(every: 15m, fn: last, createEmpty: true)
  |> fill(usePrevious: true)

However it doesn’t appear to fill the gaps.

P.S.: In the beginning of the message I wrote that I ‘need’ this, however in case it is not possible it is probably not a big deal because in such case I can implement this transformation in external app code. Just wanted to make sure I am not missing a way to do this transformation in DB


I have just solved this problem.
If the problem is still present, then code written below works like you wanted:

  |> aggregateWindow(every: 15m, fn: last, createEmpty: false)
  |> aggregateWindow(every: 15m, fn: mean, createEmpty: true)
  |> fill(usePrevious: true)
1 Like

Thanks for solving @tirex!