# Top 20 paths sorted by latency

**URL:** <https://community.grafana.com/t/top-20-paths-sorted-by-latency/127100>\
**Category:** Bar Gauge Panel\
**Created:** [July 25, 2024, 1:36pm UTC](https://community.grafana.com/t/top-20-paths-sorted-by-latency/127100 "2024-07-25T13:36:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![desecho](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/desecho/32/47487_2.png) [@desecho](https://community.grafana.com/u/desecho)\
**Post date:** [July 25, 2024, 1:36pm UTC](https://community.grafana.com/t/top-20-paths-sorted-by-latency/127100/1 "2024-07-25T13:36:09Z")

</div>

I am using Grafana v10.4.1 (d94d597d84) set up on k8s.

I am trying to see the top 20 paths sorted by latency. I am having troubles using sort\_desc and topk. It’s not working, the results it shows are not sorted and not showing 20 top results but more.

I am using bar gauge visualization. I’m using Loki as a datasource.

Here’s the query I am using:

```auto
sort_desc(topk(20, sum by(path_endpoint) (rate({namespace=~"$namespace", stream=~"$stream", container=~"$container"} 
| json 
|= `$query` 
| path_endpoint =~ `.+` 
| path_endpoint !~ `/api/internal.+` 
| path_endpoint !~ `/ws` 
| __error__ =`` 
| unwrap latency [5m]
))))

```

Does anybody have an idea what could be wrong?
