Difference of InfluxDB measurement for current dashboard range

Hi All, I’d like to visualize the difference of a InfluxDB measurement for the time range of the current dashboard. For instance, if the current dashboard range is [now, now-8d] I’d like to visualize the result of: measurement(now) - measurement(now-8d).
I’ve seen in the Grafana documentation that for Prometheus there is the $__range variable that can be used for such an operation. How can I do this for InfluxDB?

Thank you!

Hi @matterch

In Flux, assuming you are using nanosecond precision, I believe you can create a new column (e.g. called PeriodTime) by converting the timeRangeStart and timeRangeStop timestamps to int, subtracting, and then converting from nanoseconds to hours:

from(bucket: "Bucket1")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "your-measurement")
  |> filter(fn: (r) => r["_field"] == "your-field")
  |> map(fn: (r) => ({  r with PeriodTime:  float(v: uint(v: v.timeRangeStop) - uint(v: v.timeRangeStart))/float(v:3600000000000)}))
1 Like