Hi,
I’m trying to build a SQL query for Timeseries. Basic query selects time, value, series and tags. Grafana understand time and as time, value as value and all others groups as series. Thus my legend includes series * tags combination.
I would like to use tags for tooltips or legend only. Thus to exclude it from building series. I this possible? I tried to use Organize fields but it provide list of fields after series are combined. Is there a way to specify a field for series and ignore others ?
Thanks.
Hello, Is my understanding of your problem correct?
You’re working with SQL queries in Grafana to create time series visualizations. Your query returns multiple columns:
- A time column
- A value column
- A series identifier column (to distinguish different series)
- Additional tag columns (with metadata you want to use in tooltips/legends)
The challenge you’re facing is that Grafana automatically combines all string columns (both your series identifier and your tag columns) to create series names. This results in cluttered legends that contain both the series name and tag information combined.
What you want is to:
- Use only specific columns to identify/name your series
- Keep the tag columns available for tooltips or legend information
- Prevent tag columns from being automatically included in the series names
You’ve tried using the “Organize fields” transformation, but found it only works after series are already combined, which doesn’t solve your root problem.
You’re looking for a way to tell Grafana which fields should be used for creating series names and which fields should be ignored when building those series names, while still keeping all the data available for display purposes.
Is this an accurate understanding of your problem?
Yes, thanks this is the situation.
There are a few approaches to try and solve this:
1. “metric” column approach
For SQL data sources (PostgreSQL, MySQL, MSSQL), you can use a special column named “metric” to control how series are named:
SELECT
$__timeGroupAlias(time_column, '5m'),
value_column,
'desired_series_name' as metric
FROM your_table
WHERE $__timeFilter(time_column)
GROUP BY time
ORDER BY 1
This is a special case where the “metric” column becomes the field name instead of being used as a label in the series name, as documented in Microsoft SQL Server query editor.
2. Use transformations to hide fields
After your query returns data, you can use the “Organize fields” transformation to hide fields you don’t want to appear in the series names:
- Add a transformation to your panel
- Select “Organize fields”
- Use the eye icon to hide the fields you don’t want to include in series names
This approach is described in Transform data documentation and has been used successfully in community solutions as mentioned in this blog post.