Wrong values being fetched

I am trying to get the previous year values sum as a single value. The expected answer is 8265 (from influxdb) but the answer being fetched in grafana is 7874. Please refer my query below:

from(bucket: “Bacnet_Network”)
|> range(start: 2022-01-01T00:00:00Z, stop: 2022-12-31T23:59:59Z)
|> filter(fn: (r) => r[“_measurement”] == “048_STEM”)
|> filter(fn: (r) => r[“sensor”] == “472200_AV_215_STEM_HEAT_GJ_IMPORT_AV” or r[“sensor”] == “472200_AV_210_STEM_HRC2_GJ_EXPORT_AV”)
|> aggregateWindow(every: 1mo, fn: mean, createEmpty: false)
//|> group(columns: [“sensor”])
|> sum(column: “_value”)
|> keep(columns: [“_value”])
|> drop(columns: [“host”, “system”, “unit”, “topic”, “objects_type”, “name”, “_measurement”])

can anyone help me with the issue in my query since I have tried all possible ways?

Welcome @asingh25

What happens when you remove the aggregateWindow() function?

EDIT: Nevermind, that probably won’t help.

You said that in InfluxDB, the same query yields 8625. Are you sure that Grafana is not using a different time zone or time offset?

I think there is something going on here:

keep returns only the _value column, it drops everything else, so the drop after that is useless.

from the query I am assuming sensor is a tag, and your results are grouped in 2 different “sensors”. when you dropped all other columns with keep, instead of having 2 tables with 1 row (each sensor with its total), you now have 1 single table with 2 _value rows.

and in stat panel you are selecting to calculate last value, try total to get the sum of those 2 rows instead of the last one.

Thanks for responding, It seems like I was given half information.