Can't show tag as column

Hi all, I’m new to Grafana and have what I think is a simple query, however, I just can’t work this out. the query works as expected in InfluxDB 2.7.1

Version Garafana 10.01

I’m trying to show the “sensor_id” in a column, the id is a tag and a string.

This is the query

from(bucket: "volt_sense")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "mqtt_consumer")
  |> filter(fn: (r) => r["level"] == "${q_level}")
  |> filter(fn: (r) => r["area"] == "${q_area}")
  |> filter(fn: (r) => r["location"] == "${q_location}")
  |> filter(fn: (r) => r["_field"] == "A0" or r["_field"] == "A1" or r["_field"] == "A2" or r["_field"] == "A3" )
  |> pivot(rowKey:["_time"], columnKey: ["_field"], valueColumn: "_value") 
  |> keep(columns: ["_time", "_value", "sensor_id","A0", "A1", "A2", "A3"])
  |> yield(name: "last")

However, I only get this as an output

I would have expected to see the “sensor_id” as one of my columns.

Any help would be greatly appreciated


Hi @dirkeisner

What happens if you insert this line as an additional filter? (not sure about your actual tag name being used, so I guessed, but this is probably close)

|> filter(fn: (r) => r["sensor_id"] == "${sensor_id}")

Hi @dirkeisner ,
I found out that keep() function causes this issue because when I comment it out all tags are automatically displayed as columns in table. Also, when I use drop() function instead of keep() (in order to drop specific tags/columns) this issue does not occur.

However, you can work around this issue by using Grafana transformation “Labels to fields”:

This transformation changes time series results that include labels or tags into a table where each label keys and values are included in the table result. The labels can be displayed either as columns or as row values.


Best regards,