I am quite new to influx queries and I struggle with the syntax a lot.
What I want to do is to get the data for only the first day of the month. I tried this:
Hi @yves and welcome to the Influx Community Forum.
This can indeed be a bit tricky. There may be better ways to handle this using Flux, but this should work.
import "date" // The date package provides date and time constants and functions.
firstDayOfMonth = date.truncate(t: now(), unit: 1mo) // gets the current time (`now()`), and then truncates it to the beginning of the month (`1mo`) effectively giving you a timestamp for the first day of the current month.
from(bucket: "tasmota")
|> range(start: firstDayOfMonth, stop: date.add(d: 1d, to: firstDayOfMonth)) // date.add() adds a duration to a time value and returns the resulting time value.
|> filter(fn: (r) => r["_measurement"] == "tasmota")
|> filter(fn: (r) => r["_field"] == "ENERGY_Total")
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> last()