Plotting data from influx with another columns value as series legend

Hi,

I have some data in influxdb which I pivot so I can filter when a specific column is at certain value. The result I get is something like this:


When I try to graph this everything is working aside from the fact the legend uses the name http_reqs_duration.avg and nothing else. How I can make it use the corresponding value from the endpoint column?

My original data has a tag for each endpoint, but that seems to get lost once I run a pivot operation. I cannot find a way around it. The same query works fine in data explorer on influx and the legends are the endpoint tags, but on grafana it just doesn’t want to play ball.