Window Period Question

Hi all,
Trying to create a cell where it takes the average output of 7 days.
Here is the query of the cell

from(bucket: "Initial Bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "boltdb_reads_total")
  |> filter(fn: (r) => r["_field"] == "counter")
  |> aggregateWindow(every: 7d, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Question is, the same dashboard has a graph cell and if I were to change the window period of the top right (Past X time), will this affect the query of the Mean 7 days too?
For example, I would want to view the past 1h data of data, would the top right drop function supersede the query statement?

As you’re query is written, yes. The timr range selector controls the value of v.timeRangeStart and v.timeRangeStop. If you want to query a fixed time frame, just replace those variables with static values. And you don’t need to use aggregateWindow() for this operation either. You can just use mean().

from(bucket: "Initial Bucket")
    |> range(start: -7d, stop: now())
    |> filter(fn: (r) => r["_measurement"] == "boltdb_reads_total")
    |> filter(fn: (r) => r["_field"] == "counter")
    |> mean()
    |> yield(name: "mean")

One thing to note, I see that your field name is counter, which is typically a convention used when querying data from a Prometheus source to represent data that is monotonically increasing (only going up). If that’s the case, I’d suggest using increase() (to normalize any counter resets) and difference() to return only the changes between points. Then average that. So it’d look like this:

from(bucket: "Initial Bucket")
    |> range(start: -7d, stop: now())
    |> filter(fn: (r) => r["_measurement"] == "boltdb_reads_total")
    |> filter(fn: (r) => r["_field"] == "counter")
    |> increase()
    |> difference()
    |> mean()
    |> yield(name: "mean")

There’s docs on working with Prometheus metrics in Flux here: Work with Prometheus counters | Flux 0.x Documentation

Ah. Makes sense to use the range instead of aggregate window!

    |> range(start: -7d, stop: now())

The field name im using is just some random data I selected since the actual data is on site but thanks for the tip! Will note it down if im using any counters.

Thanks @scott!

No problem. Happy to help!