# Measurement exploration FLUX

**URL:** <https://community.influxdata.com/t/measurement-exploration-flux/24553>\
**Category:** InfluxDB 2\
**Created:** [April 7, 2022, 10:40am UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553 "2022-04-07T10:40:24Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex1510](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/alex1510/32/3613_2.png) [@alex1510](https://community.influxdata.com/u/alex1510)\
**Post date:** [April 7, 2022, 10:40am UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/1 "2022-04-07T10:40:24Z")

</div>

Hello,

I am desperated trying to build what should be a simple query. I want to build a “Data Exploration” dashboard in grafana in the same way as Chronograf does but I am blocked on the last query. The idea is to have 3 drop down menu in Grafana, first filtering by bucket, second, filtering by topic (tag) and third, showing all the measurements of the topic with selected tag (topic) value. I hope someone could help me on the topic:

1. Query: Filter bucket

```auto
buckets()

```

1. Query: Filter by tag called topic

```auto
import "influxdata/influxdb/v1"
v1.tagValues(
    bucket: v.bucket,
    tag: "topic",
    predicate: (r) => true
)

```

1. Query: Filter by bucket + tag.

```auto
import "influxdata/influxdb/v1"
v1.measurements(bucket: v.bucket)

```

But I don’t know how to include the filter by tag(topic)== something.

Thanks in adavance,

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 7, 2022, 3:34pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/2 "2022-04-07T15:34:22Z")

</div>

@alex1510 I’m not sure I fully understand your use case and I’m wondering if this is a misunderstanding of InfluxDB semantics and data structure. Are you trying to list **measurements** with a tag or list **fields** with a tag?

A [measurement](https://docs.influxdata.com/influxdb/v2.1/reference/glossary/#measurement) is a logical container for grouping fields and tags. Measurements contain tags and fields.

It is possible to get a list of measurements with a specific tag, but it’s an incredibly expensive query. It essentially has to query _all_ the data in your database from a given time range.

---

<div class="post-metadata">

**Author:** ![alex1510](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/alex1510/32/3613_2.png) [@alex1510](https://community.influxdata.com/u/alex1510)\
**Post date:** [April 19, 2022, 7:21am UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/3 "2022-04-19T07:21:26Z")

</div>

Hello @scott , sorry for the late reply but I didn’t receive any notification from the forum…I need to have a look…  
I will try to explain the question with the screenshot:

 ![Capture](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/6/63a9822d0642880e8f40ce5954a10ad4ae499d24.png)

First filter (red line): The user will be able to select the bucket that will be used for following filters.  
Second filter (blue line): The user will be able to select the tag that will be used for filtering the measurements.  
Third filter: The user will be able to select the measurement that wants to display.

Basically all the measurements come from different machines in the shopfloor that are publising data to a MQTT broker. Depending on the plant, measurements are stored in different buckets. Production line name (topic in mqtt) is stored as tag in the measurement.

I hope now you have a better understanding of the global need.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 19, 2022, 10:49pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/4 "2022-04-19T22:49:23Z")

</div>

Ok, I think these are what you’re looking for:

#### Get a list of buckets

```javascript
buckets()

```

#### Get a list of tags in a bucket

```javascript
import "influxdata/influxdb/schema"

schema.tagValues(
    bucket: v.bucket,
    tag: "topic",
    predicate: (r) => true,
    start: -30d,
)

```

#### Get a list of measurements with that tag

```javascript
from(bucket: v.bucket)
    |> range(start: -30d)
    |> filter(fn: (r) => r.topic == v.prod_line)
    |> group()
    |> distinct(column: "_measurement")

```

#### Query that uses all the selected variables

```javascript
from(bucket: v.bucket)
    |> range(start: -30d)
    |> filter(fn: (r) => r.topic == v.prod_line)
    |> filter(fn: (r) => r._measurement == v.measurement)

```

---

<div class="post-metadata">

**Author:** ![alex1510](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/alex1510/32/3613_2.png) [@alex1510](https://community.influxdata.com/u/alex1510)\
**Post date:** [April 20, 2022, 5:38am UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/5 "2022-04-20T05:38:38Z")

</div>

Hello @scott , sorry but it does not work…

I have tried to include the query as template variable and also to include the query directly but none of them returns anything. I have also slightly modify your query following Chronograf editor with no luck…

 ![Capture](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/f/fd8a06dab4a39a06d635b7ad7b8badab4b8aecb8.png)

The only thing I want to reproduce in Grafana is the same behavior I can do with Chronograf. Filter by bucket, filter by tag=topic and list all the measurements…that’s all.

 ![Capture2](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/f/f880a2839a667a03c1afa764bd64e7c66ff8a79b.png)

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 20, 2022, 1:31pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/6 "2022-04-20T13:31:20Z")

</div>

@alex1510 Should `PRODLINE` have an underscore in it?

---

<div class="post-metadata">

**Author:** ![alex1510](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/alex1510/32/3613_2.png) [@alex1510](https://community.influxdata.com/u/alex1510)\
**Post date:** [April 20, 2022, 2:12pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/7 "2022-04-20T14:12:36Z")

</div>

@scott , underscore is just related to “name” and “label”. But as you can see, variable name is without underscore.

 ![Capture3](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/4/4e8d0f467c01eb398fafc01e06745107e11817b3.png)

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 20, 2022, 2:27pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/8 "2022-04-20T14:27:24Z")

</div>

@alex1510 Gotcha. What’s the output of:

```javascript
from(bucket: "${BUCKET}")
    |> range(start: -30d)
    |> filter(fn: (r) => r["topic"] == "${PRODLINE}")

```

---

<div class="post-metadata">

**Author:** ![alex1510](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/alex1510/32/3613_2.png) [@alex1510](https://community.influxdata.com/u/alex1510)\
**Post date:** [April 20, 2022, 2:37pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/9 "2022-04-20T14:37:38Z")

</div>

![Capture4](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/4/4f054a82a0fb41955f35602158d9a434b9d2974b.png)  
 ![Capture5](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/a/a005fa224db906740ad4f7f95fd4f8637ce9d474.png)

Better but still getting “false”

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 20, 2022, 2:56pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/10 "2022-04-20T14:56:35Z")

</div>

I don’t know why that would return `false`. That query should return all the data where `topic` equals the selected `PROD_LINE`. It’s been a while since I’ve messed with Grafana variables, but I wonder if the Grafana will only pull variable values from the `_value` column of the query results. Try this:

```javascript
from(bucket: v.bucket)
    |> range(start: -30d)
    |> filter(fn: (r) => r.topic == v.prod_line)
    |> group()
    |> distinct(column: "_measurement")
    |> rename(columns: {_measurement: "_value"})

```

---

<div class="post-metadata">

**Author:** ![alex1510](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/alex1510/32/3613_2.png) [@alex1510](https://community.influxdata.com/u/alex1510)\
**Post date:** [April 20, 2022, 3:08pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/11 "2022-04-20T15:08:12Z")

</div>

No data

 ![Capture7](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/2/29b7607b63d5aeec174d256bb8aa5309357ba8c1.png)

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 20, 2022, 6:12pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/12 "2022-04-20T18:12:30Z")

</div>

@alex1510 Do you get no results from that query if you remove `distinct()` and `rename()`??

---

<div class="post-metadata">

**Author:** ![alex1510](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/alex1510/32/3613_2.png) [@alex1510](https://community.influxdata.com/u/alex1510)\
**Post date:** [April 21, 2022, 5:24am UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/13 "2022-04-21T05:24:35Z")

</div>

Hi, I have “v”

 ![Capture](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/a/a275ea348f0f97d36410994f0bcfeaa18c8e8727.png)

And from Chronograf:

 ![Capture2](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/3/383be6b818b6676cd40084fd16b4e09dce138656.png)

---

<div class="post-metadata">

**Author:** ![alex1510](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/alex1510/32/3613_2.png) [@alex1510](https://community.influxdata.com/u/alex1510)\
**Post date:** [April 21, 2022, 7:27am UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/14 "2022-04-21T07:27:55Z")

</div>

Hello,

I found the following topic and it helped me to write the query:

> **[Schema Queries in Flux (formerIy) IFQL | Blog | InfluxData](https://www.influxdata.com/blog/schema-queries-in-ifql/)**
>
> InfluxQL facilitates schema exploration via a number of meta queries, which include SHOW MEASUREMENTS , SHOW TAG KEYS , SHOW TAG VALUES and SHOW FIELD KEYS.

I don’t know if it is well optimized…at least it works. Do you know if it could be improved and it time range could be removed just to avoid loosing some tags that maybe does not change in the last 30d?

```auto
from(bucket: "${BUCKET}")
  |> range(start: -30d)
  |> filter(fn: (r) => r.topic == "${PRODLINE}")
  |> group(columns: ["_measurement"], mode:"by")
  |> distinct(column:"_measurement")
  |> group()

```

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [April 22, 2022, 2:46pm UTC](https://community.influxdata.com/t/measurement-exploration-flux/24553/15 "2022-04-22T14:46:04Z")

</div>

InfluxDB doesn’t allow “unbounded” queries, so you have to provide a time range, but you can do longer than 30 days.
