# Grafana query value error not sure if my query statement is wrong

**URL:** <https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403>\
**Category:** InfluxDB 2\
**Tags:** grafana\
**Created:** [August 22, 2024, 9:00am UTC](https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403 "2024-08-22T09:00:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tengdagg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/tengdagg/32/16089_2.png) [@tengdagg](https://community.influxdata.com/u/tengdagg)\
**Post date:** [August 22, 2024, 9:00am UTC](https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403/1 "2024-08-22T09:00:33Z")

</div>

Hi guys！

These queries are from my query under influxdbv2

1. 

```auto
from(bucket: "nginx_prod")
  |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "nginx_log")
  |> filter(fn: (r) => r["server_name"] == "www.test.com:9988")  
  |> count()

```

Its value is 1,051,093.

1. 

```auto
from(bucket: "nginx_prod")
  |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "nginx_log")
  |> filter(fn: (r) => r["server_name"] == "www.test.com")  
  |> count()

```

Its value is 213,895

1. 

```auto
from(bucket: "nginx_prod")
  |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "nginx_log")
  |> filter(fn: (r) => r["server_name"] == "www.test.com:6688")  
  |> count()

```

Its value is 11,322

However, I queried the values in grafana to try to sort them, and the query doesn’t look quite the same as the values I queried in my influxdb, and this is my query statement in grafana

```auto
from(bucket: "nginx_prod")
  |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "nginx_log")
  |> group(columns: ["server_name"])
  |> count()
  |> group()
  |> sort(columns: ["_value"], desc: true)
  |> limit(n: 10)

```

The query looks like this

[www.test.com:9988](http://www.test.com:9988) value 15766306  
[www.test.com](http://www.test.com) value 3208172  
[www.test.com:6688](http://www.test.com:6688) value 169826

The values queried in Grafan and the values I queried in the database are way too different, is there a problem with my query statement in Grafana, please help me out!

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [August 22, 2024, 8:27pm UTC](https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403/2 "2024-08-22T20:27:38Z")

</div>

@tengdagg Just to confirm, the query that you’re running in Grafana is using a statically defined time range and is _not_ using the timerange variables (`v.timeRangeStart`, `v.timeRangeStop`)?

How are you running the queries in InfluxDB (that filter by specific by a specific tag value)? In the data explorer? In a dashboard cell? If in a dashboard cell, what type of visualization are you using?

One discrepancy between the queries is that the ones you’re running in InfluxDB use the default group key (by measurement and all tags) while the one you’re running in Grafana groups by `server_name`. `count()` operates on each group/table. I’d recommend updating the queries you’re running in InfluxDB to use the same grouping before executing a `count()`:

```javascript
from(bucket: "nginx_prod")
  |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "nginx_log")
  |> filter(fn: (r) => r["server_name"] == "www.test.com:9988")
  |> group(columns: ["server_name"])
  |> count()

```

```javascript
from(bucket: "nginx_prod")
  |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "nginx_log")
  |> filter(fn: (r) => r["server_name"] == "www.test.com")
  |> group(columns: ["server_name"])
  |> count()

```

```javascript
from(bucket: "nginx_prod")
  |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "nginx_log")
  |> filter(fn: (r) => r["server_name"] == "www.test.com:6688")
  |> group(columns: ["server_name"])
  |> count()

```

---

<div class="post-metadata">

**Author:** ![tengdagg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/tengdagg/32/16089_2.png) [@tengdagg](https://community.influxdata.com/u/tengdagg)\
**Post date:** [August 23, 2024, 9:17am UTC](https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403/3 "2024-08-23T09:17:05Z")

</div>

@scott  
I want to count the number of requests for server\_name in grafana in this specific time period and rank them in descending order of Top10.  
|\> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)  
Both grafana and influxdb times are like this This time I just conducted a test

```auto
from(bucket: "nginx_prod")
  |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "nginx_log")
  |> group(columns: ["server_name"])
  |> count()
  |> group()
  |> sort(columns: ["_value"], desc: true)
  |> limit(n: 10)

```

This query is a query test for my explorations in grafana, and because of the differences in the data, I have queried the specific domains with differences in influxdb, is there a problem with the query statement in grafana that leads to the different number of results? Is there something wrong with my query statement in grafana that is causing the difference in the number of results?

The query value is not correct in influxdb either, I feel like there is something wrong with my query statement

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/3X/7/b/7b93d41e20086c89a54fa7da0ccd3784d2cfda58.png)

My most queried domain alone has just over 1 million requests in 24 hours but the query yielded over 10 million results

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [August 26, 2024, 4:06pm UTC](https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403/4 "2024-08-26T16:06:34Z")

</div>

> [@tengdagg](#):
>
> My most queried domain alone has just over 1 million requests in 24 hours but the query yielded over 10 million results

What fields do you have in this measurement?

---

<div class="post-metadata">

**Author:** ![tengdagg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/tengdagg/32/16089_2.png) [@tengdagg](https://community.influxdata.com/u/tengdagg)\
**Post date:** [August 28, 2024, 3:11am UTC](https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403/5 "2024-08-28T03:11:32Z")

</div>

> [@tengdagg](#):
>
> ```auto
> from(bucket: "nginx_prod")
> |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
> |> filter(fn: (r) => r["_measurement"] == "nginx_log")
> |> group(columns: ["server_name"])
> |> count()
> |> group()
> |> sort(columns: ["_value"], desc: true)
> |> limit(n: 10)
> 
> ```

@scott  
There are only these fields in this query

 ![WX20240828-111037](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/3X/3/5/3596fa384cbe26b075ec438f863e402029492f71.png)

There are no other fields.

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [August 28, 2024, 2:13pm UTC](https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403/6 "2024-08-28T14:13:57Z")

</div>

Run this query for me:

```javascript
import "influxdata/influxdb/schema"

schema.measurementFieldKeys(bucket: "nginx_prod", measurement: "nginx_log")

```

---

<div class="post-metadata">

**Author:** ![tengdagg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/tengdagg/32/16089_2.png) [@tengdagg](https://community.influxdata.com/u/tengdagg)\
**Post date:** [September 3, 2024, 6:57am UTC](https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403/7 "2024-09-03T06:57:32Z")

</div>

@scott Hi scott I used this query you gave me and the query looks like this

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/3X/d/f/df74b8cd37557779d59e917c0e98ae4e6c7c19d4.png)  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/3X/b/c/bcaa3ba7f68b208fc70aa326829bee7d443948c7.png)  
 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/3X/f/f/ff67dacd89063f3470dd79064ca8a2f7da9fc60a.png)  
My server\_name is of tag type, otherwise the query is very slow

---

<div class="post-metadata">

**Author:** ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)\
**Post date:** [September 4, 2024, 5:32pm UTC](https://community.influxdata.com/t/grafana-query-value-error-not-sure-if-my-query-statement-is-wrong/35403/8 "2024-09-04T17:32:18Z")

</div>

Ok, the reason I ask what fields exist is because you’re not filtering by field, so the numbers you’re calculating are actually the sum of points across all fields. I don’t think that’s what you’re looking for. I’d suggest filter by _a_ field, just to limit the count to a single field:

```javascript
from(bucket: "nginx_prod")
  |> range(start: 2024-08-21T00:00:00Z, stop: 2024-08-22T00:00:00Z)
  |> filter(fn: (r) => r["_measurement"] == "nginx_log")
  |> filter(fn: (r) => r["_field"] == "request")
  |> group(columns: ["server_name"])
  |> count()
  |> group()
  |> sort(columns: ["_value"], desc: true)
  |> limit(n: 10)

```
