Last() value within a time range

I’m not quite sure how to ask what I’m after, so I’ll try and explain:

I’m querying thermocouple data from an InfluxDb on a panel setup with this query:

from(bucket: v.bucket)
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Thermocouple")
  |> filter(fn: (r) => r["Sensor"] == "01" or r["Sensor"] == "04" or r["Sensor"] == "07")
  |> filter(fn: (r) => r["_field"] == "value")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: true)

This panel is on a dashboard with a 5 minute window.

I also have a stat that displays a moving trend figure using this query:

from(bucket: v.bucket)
  |> range(start: -5s, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Temperature_trend")
  |> filter(fn: (r) => r["Sensor"] == "01")
  |> filter(fn: (r) => r["_field"] == "value")
  |> last()

I’ve set the time range start to be ‘-5s’ in the query so that I can ensure it is showing the latest figure and if it can’t get one it’ll show ‘No data’.

The problem
If I use the dashboard to analyse historic data the single stats don’t work because the ‘-5s’ in their query clashes with the new dashboard time window range. Of course if I set the stats time window start to be ‘v.timeRangeStart’ it will work when analysing historic data, but they don’t perform as I want for live data.

The question
What’s the best way around this, without having 2 different stat panels?


Hi @olliecampbell

If you want just certain panels to display certain time ranges, use the Query Options:

and you will see this:

(note that this will override the time selector drop down)

Is that what you are trying to do?

I’m getting something a little strange. If I restrict the ‘Relative time’ to anything less than 8s (the data is being reported every 1s) I get ‘No data’.
A ‘Relative time’ setting of >8s and it seems to work.

This panel was refreshed at 15:02:22 and pulled in the last() point 1 second earlier. So why would a ‘Relative time’ of 1s or 2s not work?

Just bumping this to see if anyone else can help, or give me some points as to where I’m going wrong?

Maybe this will help?
Here is some temperature data that gets sent to InfluxDB every 15 seconds:

If I change the Relative time to 45 seconds, I get this (3 points, because that’s all there is over the past 45 seconds). Notice that the time selector remains at Last 15 minutes, but this value gets overridden by the relative time field.

Changing the Relative time to 15 seconds, I get only 1 point (because that’s all there is over the past 15 seconds).

Any value in the Relative time field of less than 15 seconds (the frequency at which readings are populated/stored in the database) means we will get No Data.

At what time interval is your data populated/stored in InfluxDB? Every second? Every 30 seconds? I am guessing it is every 8 seconds or so.


So I’ve had to move my installation to newer hardware and for some reason this is now working as expected where it wasn’t on the old hardware.

Thanks for taking the time to help.