# Flux: Distinct grouping of addresses

**URL:** <https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122>\
**Category:** InfluxDB\
**Tags:** flux\
**Created:** [November 19, 2023, 2:35pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122 "2023-11-19T14:35:48Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![dieterlind](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dieterlind](https://community.grafana.com/u/dieterlind)\
**Post date:** [November 19, 2023, 2:35pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/1 "2023-11-19T14:35:48Z")

</div>

Hello!

I have the following topic.  
Let’s say I have the following data

```auto
18.11.2023 13:00 Address_1
18.11.2023 14:00 Address_2
18.11.2023 15:00 Address_1
18.11.2023 16:00 Address_3
18.11.2023 17:00 Address_1

```

I want to draw a bar chart showing me groupd by address the number of visits in the choosen time periode. Like:

```auto
Address_1 3
Address_2 1
Address_3 1

```

Unfortunately I am not able to combine group, count, … to reach the right result

From searching I tried different hints … but none worked e…g

```auto
from(bucket: "iobroker")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
    |> filter(fn: (r) => r["_measurement"] == "Adresse" and r["_field"] == "value")
 |> duplicate(column: "_value", as: "new_column")
  |> group(columns: ["new_column"])
  |> count()

```

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [November 19, 2023, 2:46pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/2 "2023-11-19T14:46:06Z")

</div>

Hi @dieterlind

How about something like this?

```auto
from(bucket: "your_bucket")
  |> range(start: 2023-11-18T13:00:00Z, stop: 2023-11-18T17:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "your_measurement") // Replace with your actual measurement name
  |> group(columns: ["_field"])
  |> count(column: "_value")
  |> yield(name: "count")

```

---

<div class="post-metadata">

**Author:** ![dieterlind](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dieterlind](https://community.grafana.com/u/dieterlind)\
**Post date:** [November 19, 2023, 3:53pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/3 "2023-11-19T15:53:04Z")

</div>

This results in:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/8/1/81532d99fafc8ce11bb65bd74bc46fcab65a40b9.png)

Actually I just want the different “values” on the left side and the count(distinct) on the right side …

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [November 19, 2023, 11:53pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/4 "2023-11-19T23:53:50Z")

</div>

What are all the possible values for \_measurement? If its Address\_1, Address\_2, etc. then try changing these lines as shown & report back…

```auto
  |> group(columns: ["_measurement"])
  |> count()

```

---

<div class="post-metadata">

**Author:** ![dieterlind](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dieterlind](https://community.grafana.com/u/dieterlind)\
**Post date:** [November 20, 2023, 1:49pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/5 "2023-11-20T13:49:34Z")

</div>

Hi!

Yes, it can be several addresses which occur 1 - n times and shall be grouped.

After changing I get

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/e/3/e394c5070329b727768c097284a1fd3c9f1fe7fb.png)

So the result is the total number of addresses found but not grouped by addresses  
The different addresses are in the “\_value” column

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [November 20, 2023, 3:36pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/6 "2023-11-20T15:36:31Z")

</div>

What happens if you put a [distinct function](https://docs.influxdata.com/flux/v0/stdlib/universe/distinct/#:~:text=distinct()%20returns%20all%20unique,own%20distinct%20value%20if%20present.) before the count function, like this?

```auto
|> distinct(column: "_measurement")

```

---

<div class="post-metadata">

**Author:** ![dieterlind](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dieterlind](https://community.grafana.com/u/dieterlind)\
**Post date:** [November 20, 2023, 4:11pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/7 "2023-11-20T16:11:33Z")

</div>

like this?

```auto
from(bucket: "iobroker")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Adresse")
  |> group(columns: ["_measurement"])
  |> distinct(column: "_measurement")

```

gives an error  
`Status: 500. Message: invalid: runtime error @5:6-5:38: distinct: schema collision: cannot group boolean and string types together`

this also doesn’t work with the same error:

```auto
from(bucket: "iobroker")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Adresse")
  |> group()
  |> distinct(column: "_measurement")

```

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [November 20, 2023, 5:15pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/8 "2023-11-20T17:15:36Z")

</div>

How about this…Could you run this query in Influx Data Explorer and then upload here the csv of the output? That will make it easier for the community to evaluate and help you find a solution.

```auto
from(bucket: "iobroker")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Adresse" and r["_field"] == "value")
  |> yield(name: "help")

```

---

<div class="post-metadata">

**Author:** ![dieterlind](https://avatars.discourse-cdn.com/v4/letter/d/a88e57/32.png) [@dieterlind](https://community.grafana.com/u/dieterlind)\
**Post date:** [November 20, 2023, 5:22pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/9 "2023-11-20T17:22:02Z")

</div>

If the csv-export button would still be available I could provide it … but somehow this is gone

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/2/9/293bf964c3793eead50dce0c934299687ac7bbe9.png)

wasn’t the button typically next to the timeframe to select or “view raw data”?

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [November 20, 2023, 6:22pm UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/10 "2023-11-20T18:22:18Z")

</div>

Something like

```auto
measurement,tag1,location,.parking-position.latitude,time
.parking-position.latitude,parking,Accord,41.7972,1700152037000000873

measurement,tag1,location,.parking-position.longitude,time
.parking-position.longitude,parking,Accord,-74.2319,1700152037000000873

```

Type it in here manually

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [November 21, 2023, 12:36am UTC](https://community.grafana.com/t/flux-distinct-grouping-of-addresses/108122/11 "2023-11-21T00:36:39Z")

</div>

> [@dieterlind](#):
>
> wasn’t the button typically next to the timeframe to select or “view raw data”?

I think it was last seen in v2.6

Maybe you can copy/paste the data (or at least ~10 representative lines) so we can try to help you.
