# Limit the number of results in a range vector?

**URL:** <https://discuss.prometheus.io/t/limit-the-number-of-results-in-a-range-vector/2367>\
**Category:** PromQL\
**Created:** [August 1, 2024, 11:14pm UTC](https://discuss.prometheus.io/t/limit-the-number-of-results-in-a-range-vector/2367 "2024-08-01T23:14:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![crodie](https://avatars.discourse-cdn.com/v4/letter/c/c37758/32.png) [@crodie](https://discuss.prometheus.io/u/crodie)\
**Post date:** [August 1, 2024, 11:14pm UTC](https://discuss.prometheus.io/t/limit-the-number-of-results-in-a-range-vector/2367/1 "2024-08-01T23:14:17Z")

</div>

Hello,  
I am trying to limit the results returned in range vector. I tried using `topk` to limit my return but it is returning more than n specified.

I found this on the web:

> This is because it returns top `N` time series independently per each timestamp on the graph.  
> [docs](https://stackoverflow.com/a/71561315)

Here is an example of a query I am trying to plot on grafana:

```auto
topk(5,
sum by (service) (traefik_service_request_duration_seconds_sum{service=~"$service.*",protocol="http"} )/ 
sum by (service) (traefik_service_request_duration_seconds_count{service=~"$service.*",protocol="http"})
)

```

How would I limit my result to just 5 services ? Is there a work around for this? I see someone recommend using topk\_max in the docs, but prometheus uses promql and not sure how I can use metricsSql with it.  
Grafana V 8.3.4  
Thank you for your time!
