Grafana sort repeating panel based on panel value from prometheus

Hi Team,
I came across one scenario of sorting and am not sure how to achieve this. Can someone please help?

I have a Prometheus query for the Panel, which shows the latency value in Gauge unit- seconds (s)
max_over_time(max by(name)(histogram_latency_seconds{Label=“$label”,quantile=“$Quantile”, env=“u”at,from=“kafka_phlegethon”})[$__range:$__interval])

Also, this panel is repeated based on the Label. I need to sort these all panels by their value. Is that doable?

Thank you!

I attempted to utilize the query_result variable but encountered issues. My Prometheus query is dynamic, relying on variables such as labels, quantiles, range, and interval. When attempting to sort the result using query_result(sort( Query)) , the outcome is empty. Additionally, the sorting action only takes place on dashboard load or range change, limiting its effectiveness when dealing with dynamically changing query results.