Flux custom "movingSpread" aggregate function

Hello,

Currently on InfluxDB v2.0.5 and using Grafana v7.5.6 for visualization. I originally posted this question on Grafana forum thinking this would be solved with Grafana transformations, but I’m now thinking it may be better solved with Influx.

I need a movingSpread() function that will work similar to movingAverage() except it returns the spread :slight_smile:
something like:

from(bucket:"mybucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "TimeDomain")
  |> filter(fn: (r) => r["Channel"] == "Ch0")
  |> filter(fn: (r) => r["_field"] == "value")
  |> movingSpread(n: # of points)
  |> yield()

Is something like this possible? If so, does anyone have any pointers on how I could create this function? I’m currently going through the docs but the dots are not connecting for me yet. Thank you!

Turned out to be a one liner if the moving spread is based on time rather than number of points : )

from(bucket:"mybucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "TimeDomain")
  |> filter(fn: (r) => r["Channel"] == "Ch0")
  |> filter(fn: (r) => r["_field"] == "value")
  |> aggregateWindow(every: Ns, fn: spread, createEmpty: false)
  |> yield()
1 Like