Change legend name according to result from sql query

I am trying to config my legend from result of sql query based on the repeated variable value, give the legend a user-friendly name to show on dashboard. I am trying to use key-value variable, which only show name in selection drop down menu, not able to get the the name. If I config 2 variable, but how could make 2 variable sync with each other, one is id for query, one is name for display?

welcome to the :grafana: forum, @

can you share some screenshots? Have you explored some public dashboards on play.grafana.org to see how they are configuring aliases and templates for the legend?

and what datasource are using? the core mysql or postgres datasource plugin?