Filter measurements names based on a tag value

I want to filter measurements names based on a tag value.
I have multiple measurements in a bucket, all measurements have a tag called “enabled”.
I can simply get all measurements names with the following flux query:

import “influxdata/influxdb/v1”
v1.measurements(bucket: v.bucket)

but how to only get back measurements names where the value of the “enabled” tag is equal to “True”?

@Saleh This should give you what you want:

from(bucket: v.bucket)
    |> range(start: -30d)
    |> filter(fn: (r) => r.enabled == "True")
    |> group()
    |> distinct(column: "_measurement")

Hi scott thank you for your answer, this gives me the following error:

distinct: schema collision: cannot group float and integer types together

but the following works:

from(bucket: v.bucket)
    |> range(start: -1d)
    |> filter(fn: (r) => r.enabled == "True")
    |> distinct(column:"_measurement")
    |> group(columns: ["_measurement"], mode:"by")
    |> group()
    |> distinct(column:"_measurement")

It’s a bit slow though, and I don’t quit get why this work and not your suggested query.

By default, data returned from InfluxDB is already grouped by measurement. But this means that each unique measurement in your steam of tables is structured as a unique table. distinct() operates on each table, not the stream of tables as a whole.

The reason that query errs is because you have fields with different types. When you try to “ungroup” (group()) data, the _value columns must be the same type.

Thinking through this a little more, I think this will give you what you’re looking for and will be the most performant:

from(bucket: v.bucket)
    |> range(start: -30d)
    |> filter(fn: (r) => r.enabled == "True")
    |> last()
    |> keep(columns: ["_measurement"])
    |> group()
    |> distinct(column: "_measurement")

thank you for the explanation, yup this works a bit faster, and looks cleaner for sure.