# Use \_field as a tag in query

**URL:** <https://community.influxdata.com/t/use-field-as-a-tag-in-query/31255>\
**Category:** Fluxlang\
**Tags:** influxdb, grafana\
**Created:** [August 23, 2023, 8:41am UTC](https://community.influxdata.com/t/use-field-as-a-tag-in-query/31255 "2023-08-23T08:41:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![OdneOksavik](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@OdneOksavik](https://community.influxdata.com/u/OdneOksavik)\
**Post date:** [August 23, 2023, 8:41am UTC](https://community.influxdata.com/t/use-field-as-a-tag-in-query/31255/1 "2023-08-23T08:41:38Z")

</div>

Hi,

I’m reading data from InfluxDB in Grafana, and I want to do alerts using multiple values.  
My data has unique \_field, but no unique tag. This is an issue in Grafana Alerts, and I would like to somehow set the \_field as a tag as well (copy).

I tried this approach:

> [@influxDB: How to convert field to tag in influxDB v2.0](https://community.influxdata.com/t/influxdb-how-to-convert-field-to-tag-in-influxdb-v2-0/21484):
>
> Hello, Is there any way to convert fields to tags on existing measurement with many points in influxDB v2.0 ? We did found the solution but for v1.8 and below. Please any help appreciated. We tried using below query to copy one measurement data into another but not sure how we can change field to tag using flux query. from(bucket: "bucket\_name") |\> range(start: -10y) |\> filter(fn: (r) =\> r.\_measurement == "cu\_om") |\> aggregateWindow(every: 5s, fn: last, createEmpty: false) |\> …

But I’m not looking to write this to a new bucket, but rather have my query return with the extra tag.

Any tips?

---

<div class="post-metadata">

**Author:** ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)\
**Post date:** [August 23, 2023, 6:36pm UTC](https://community.influxdata.com/t/use-field-as-a-tag-in-query/31255/2 "2023-08-23T18:36:53Z")

</div>

Hello @OdneOksavik,  
You can use the duplicate function()

> **[duplicate() function | Flux 0.x Documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/duplicate/)**
>
> duplicate() duplicates a specified column in a table.

But I’m not sure that this will produce tags in Grafana. (I don’t think it will).  
You might have to then group by the \_field duplicated column.

But there isn’t a way to add a tag without writing data to the database with a tag.

---

<div class="post-metadata">

**Author:** ![OdneOksavik](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@OdneOksavik](https://community.influxdata.com/u/OdneOksavik)\
**Post date:** [August 26, 2023, 7:50am UTC](https://community.influxdata.com/t/use-field-as-a-tag-in-query/31255/3 "2023-08-26T07:50:15Z")

</div>

Thank you.

I did some more research and found a post describing the same issue, and a solution:  
By adding the following to the end of my Flux query

```auto
|> rename(columns: {_value: "something"})

```

we get unique tags, and the Grafana alert works as intended.

---

<div class="post-metadata">

**Author:** ![grant1](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/grant1/32/15107_2.png) [@grant1](https://community.influxdata.com/u/grant1)\
**Post date:** [August 26, 2023, 11:12am UTC](https://community.influxdata.com/t/use-field-as-a-tag-in-query/31255/4 "2023-08-26T11:12:03Z")

</div>

Hi @OdneOksavik

It appears you were able to solve your problem, but as @Anaisdg said, the only way to get a tag into InfluxDB is the write a tag. In your case, I believe the way Grafana parses the result from InfluxDB is that if a `_value` column is found, it is assumed to be a time-series. The workaround is to add the following:

` |> rename(columns: {_value: "something"})`
