Is it possible to change legend using 'alias by' when series are selected with $variable?

Hello all,
i’m making next request:
SELECT max(/$metric$/) FROM "$measurement" WHERE "transaction"='$transactions' AND "statut"='all' AND $timeFilter group by time($group_time).
$metric variable has values: avg, min,max.
As a result i’m getting few series with max_avg, max_min and max_max labels in legend.
Is it possible change them somehow to $metric variable values(avg, min, max)?


As long as your above query works as expected you should be able to use the alias by field in grafana. Inserting $metric in the alias by field should render your selected template variable value.


Hi Marcus, thanks for your reply.

I’ve tried this variant, it is not working as expected.

For each serie i got set of all values {avg,min,max,pct90.0,pct95.0,pct99.0}, not one i need


From your screenshot it looks like you have a template variable metric defined where you have selected multiple values or all. Based on my knowledge I think you want to use repeated panels. If you do this you should be able to use $metric as alias.


No, i have 2 template variables $metric and $transaction.

On screenshot you could see how i use that metrics. Repeated panels are used for transactions(http requests) and metric variable is used to select metrics to display on each graph(avg, min, max…)

Okay gotcha.

I didn’t think that you could use multiple values of $metric in a select max($metric) expression. Does that work if you select only avg and min for example? Would be interesting to see the request/response of the query inspector for one of those graphs.

Usually I think you would have tags defining avg, min, max and filter those using template variable. Then you can use that tag as alias.