Min Max by day on multiple measurements

Hello,

I would like to get by day the min and max for each selected measurement.

below the selection query
How can I get by day the min and the max for each measurement BBRHCJC … int the same query

Thanks in advance for your support on it

data = from(bucket: "datainfo")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "BBRHCJB" or r["_measurement"] == "BBRHCJR" or r["_measurement"] == "BBRHCJW" or r["_measurement"] == "BBRHPJB" or r["_measurement"] == "BBRHPJR" or r["_measurement"] == "BBRHPJW" or r["_measurement"] == "HCHC" or r["_measurement"] == "HCHP")
  |> filter(fn: (r) => r["_field"] == "Compteur")
  |> aggregateWindow(every: 1d, fn: max, createEmpty: false)

@Franck_Bellot You can calculate the min and max in separate streams and then union them together:

data = () =>
    from(bucket: "datainfo")
        |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
        |> filter(
            fn: (r) =>
                r["_measurement"] == "BBRHCJB" or r["_measurement"] == "BBRHCJR" or r["_measurement"] == "BBRHCJW"
                    or
                    r["_measurement"] == "BBRHPJB" or r["_measurement"] == "BBRHPJR" or r["_measurement"] == "BBRHPJW"
                    or
                    r["_measurement"] == "HCHC" or r["_measurement"] == "HCHP",
        )
        |> filter(fn: (r) => r["_field"] == "Compteur")

min =
    data()
        |> aggregateWindow(every: 1d, fn: min, createEmpty: false)
        |> set(key: "_field", value: "min_Compteur")

max =
    data()
        |> aggregateWindow(every: 1d, fn: max, createEmpty: false)
        |> set(key: "_field", value: "max_Compteur")

union(tables: [min, max])

A few notes:

  • I wrote data() as a function to preserve the pushdown through to aggregateWindow(), just to make sure the query is as performant as possible.
  • I renamed the field in each stream so you know which represent the min and max.

Thanks a lot, it’s helping me a lot.
I do not understand the added value of the data() as function, that’s the first time than I see this kind of ‘step’. I will take time during week-end to get info about it :wink:

One added question
In the future, I will need to use the result, to calculate the gap value between min and max.
I have added the line pivot on measurement result by date
pivot(rowKey:[“_time”], columnKey: [“_measurement”], valueColumn: “_value”)

How can I group min and max value of all the measurements by date to be able in the future to calculate the difference/gap between min and max using map() function.

Thanks again for your support