Custom Column Name in InfluxQL query

Hello All,

I am using Grafana v8.4.10 on a Linux instance.
I have an InfluxDB datasource configured with query type as InfluxQL.

I have a list of devices for which timeseries property data is captured in influxDB.
So the property data is stored into separate measurement table for each device.

I want to display the data for all the devices at the same time in a timeseries chart.
So I have all the device list queried and stored into a variable. And to show the property data for all the devices in the chart, I am using influxDB query as below.

SELECT “time”, “propertyName” FROM /($Variable)/

This will return the property data for all the measurements (i.e. devices) together and display on the chart.

But the problem I have is the chart legend is showing each plotting in graph in format as below.
Device1.propertyName
Device2.propertyName
Device3.propertyName and so on.

Whereas I want to display it as
Device1
Device2
Device3 and so on.

How can I achieve custom column name in the query I am using to show only the measurement name as legend or column name instead of measurement.propertyName which is appearing currently.

I am hoping we can achieve this with regex, but I am not sure how to do this.
Or if there is any other way possible.

Please reach out if you have any inputs.

Thanks in advance
Bhushan

what happens if you add an alias to it

SELECT “time”, “propertyName” as metric FROM /($Variable)/

@yosiasz

Thanks for your inputs.

I have tried aliasing as below.

SELECT “time”, “propertyName” AS “” FROM /($Variable)/

This did not work if i give empty string.

If i give a single space in the alias, it removes the property name but the dot does not get removed and I get “Device.” Instead of getting just “Device”

As my dashboard panels are bigger in size that dot does not look good.

Also I tried as per what you suggested.

SELECT “time”, “propertyName” AS metric FROM /($Variable)/
Using this, I am seeing output as
Device1.metric
Device2.metric and so on.

Meaning, the property name got replaced by the metric word.

Please share if you something specific related to aliasing.

Thanks and regards
Bhushan

1 Like

If someone is looking for answer. try this
You have to use “Rename by Regex” in Transform tab(next to query) where you can match and replace in it. Example below.

Match : /.propertyName./
Replace: (give a space here)

1 Like