Date.truncate doesn't work anymore

Hi all!

I created the following flux (in my Grafana board) select to get the max value of “yesterday” values from a timeseries. I don’t want to use now() because this gives me only the relative results until the time now minus 1 day, so values up to midnight are missing. But I want all data from the complete day yesterday (00:00:00 until 23:59:59).

import “date”
from(bucket: “iobroker”)
|> range(start: date.truncate(t: now(), unit: -2d), stop: date.truncate(t: now(), unit: -1d))
|> filter(fn: (r) =>
r._measurement == “LadungSpeicherHeute” and
r._field == “value”)
|> max()

Yesterday the select works without errors and running perfect. But today after I opened my Grafana board, I got the error message:

500 Internal Server Error: error in building plan while starting program: cannot query an empty range

I checked the data rows with the above query and the following hardcoded range:
|> range(start: 2023-02-13T00:00:00Z, stop: 2023-02-13T23:59:59Z)

And this works.

Can anyone help me? Why was the date.truncate function working yesterday and today not anymore? Am I complete wrong in using date.truncate?

Or: how to get all data items of the - calendary - last day of a time series?

I am not familiar with that function, but in Grafana, if you are willing to save the dashboard panel (containing the max value of yesterday), you can fix the value in the time picker to “Yesterday” and it will correctly use all the values from yesterday. For example, yesterday the max temperature over 24 hours was indeed 51 F.

There are probably other ways to do this in either Influx or Grafana.

Yes, I know, but I want to create a panel showing data independend from the Grafana time picker. I’m using a Grafana time picker with last week, because there is a panel inside my dashboard showing the last 7 days. So I need individual time range selects in my panel InfluxDB queries.

Anyway, question to you if you know Grafana: I can solve my problem with

import “experimental/date/boundaries”
day = boundaries.yesterday()
|> range(start: day.start, stop: day.stop)

This works fine with InfluxDB Data explorer UI. But if I’m using this in Grafana InfluxDB datasource edit, I get the error

500 Internal Server Error: type error 2:1-2:38: unknown import path: “experimental/date/boundaries”

Very strange…

Obviously I’m the only person who wants to select all data of a calendary day (yesterday) from a timeseries with explicit range boundaries derived from now()

Ok, found the error. Connected the data source in Grafana to the wrong InfluxDB. :sleeping:

I have 2 instances running in docker on the same host, one instance v1.8 the other instance v2.6.1. Just the ports are different…

1 Like