I’m interested in getting data from a UI-driven time range (e.g. using v.timeRangeStart and v.timeRangeStop) and comparing it to data from 1 week before the same time range. If I could generate two tables, I can do all of the comparisons with join/math, or simply visualize both.
I can definitely take last week’s data and timeShift(duration: 7d) and turn it into this week’s timestamps.
But what I can’t figure out how to do is to do math on timeRangeStart/timeRangeStop. I was hoping I could do something like this:
The part I’m trying to address is what’s in the range() function. In your example, you have range(start: -7d, stop: -6d). What I’d like to do is to make it relative to v.timeRangeStart so I can still use the time filter selectors in the dashboard.
I figured out something this AM. Using experimental.subDuration works when v.timeRangeStart resolves to an absolute time (e.g. ‘Custom Time Range’ in the picker), but not when it is specified as a duration (e.g. ‘Past 24h’)
It seems like the type of the v.timeRangeStart argument changes based on whether it’s a absolute or relative time, and there is logic built into the range() function to resolve this. Is there a way I can make experimental.subDuration(d: 7d, from:v.timeRangeStart) work when v.timeRangeStart is in relative times?
I was trying to make a crazy workaround where I did one query (for recent data) using v.timeRangeStart/v.timeRangeStop, and then extract the value from the _start and _stop columns, but I couldn’t understand how to extract them and use them in the range() operator of the next query. I was trying to follow Extract scalar values in Flux | InfluxDB OSS 2.0 Documentation, but I couldn’t get anything to work.
I couldn’t get the alignTime to work, but I got it to work with timeShift(). I also found that I needed to add a new column to the historical and current and add it to the group key. So my working example looks like: