How would I go about creating a flux query with a range that is (for example):
Jan 01 of the current year (2023) to now.
The most recent July to now.
I tried using functions like “date.year(t: now())” a the start of the range, but it always gives me syntax errors. If someone can give me examples for the above two scenarios, I can probably decipher it from there.
Right now I am in bed but I am saving this to share with you some examples tomorrow. You are in the right track but also have in to consideration the time zone, deppending on your time zone date.year( t: now()) may give you the wrong value at the end of the yer.
date.year() btw will return only the year as an int . Maybe the other function (which I dont remember right now ) date.truncate()? with a year parameter will work better for you.
Or worst case you could interpolate in a fixed string the year with 00:00:00.000z or whatever time offset you are in, then convert to time.
import "date"
import "timezone"
option location = timezone.fixed(offset: -4h) //Now an offset is applied do all time range selections on the query
month = date.truncate(t: now() , unit: 1mo)
from(bucket: "Bucket")
|> range(start: month)
I managed to figure out what I needed via IF statements.
In the example, I basically checked to see if the current month (month(now)) is greater than 6, then created a start and stop time based on that. That basically finds the most recent July and derives the appropriate year to use from that.
Is it possible to add another column to the outputted table that includes the date (or partial date) in string form?
Map() seems to do what I want, but it creates a whole new table. Is there a ways to just append a column to the existing table, or drop the original table?