# Influxdb window question

**URL:** https://community.influxdata.com/t/influxdb-window-question/25456
**Category:** InfluxDB 2
**Tags:** influxdb, flux
**Created:** [June 17, 2022, 3:40am UTC](https://community.influxdata.com/t/influxdb-window-question/25456 "2022-06-17T03:40:36Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ryzeliu](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@ryzeliu](https://community.influxdata.com/u/ryzeliu)
#### Post date: [June 17, 2022, 3:40am UTC](https://community.influxdata.com/t/influxdb-window-question/25456/1 "2022-06-17T03:40:36Z")

</div>

Want:  
I want retrive the mean value between 2022-05-30T02:21:46.000000000Z and 2022-05-30T02:22:46.000000000Z, below is my dsl:

from(bucket:“telegraf”)  
|\> range(start:2022-05-30T02:21:46.000000000Z, stop:2022-05-30T02:22:46.000000000Z)  
|\> filter(fn: (r) =\> r["\_measurement"] == “mem”)  
|\> filter(fn: (r) =\> r["\_field"] == “used\_percent”)  
|\> aggregateWindow(every:1m, fn:mean, createEmpty:false)  
|\> group(columns:[“host”])  
|\> yield(name:“mean”)

Expected:  
one table per host

Actual:  
two table per host,

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/d/dfca72b48f48b2b115abe18333652d00938e6f08.png)

Question:

1. how to the window function work?
2. how can i get the expected result?

---

<div class="post-metadata">

### Author: ![mhall119](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/mhall119/32/3898_2.png) [@mhall119](https://community.influxdata.com/u/mhall119)
#### Post date: [June 17, 2022, 2:39pm UTC](https://community.influxdata.com/t/influxdb-window-question/25456/2 "2022-06-17T14:39:14Z")

</div>

Your screenshot shows one table per host (you have 3 hosts, and 3 tables).

It shows two _values_ for each host though. I suspect what’s happening is that the `start` and `stop` in `range` is inclusive, so you’re actually asking for 61 seconds worth of data, not 60 seconds exactly. This means your `aggregateWindow` function has slightly more than one minute’s worth of data, and so it will produce two sets of outputs.

If you are always going to limit your `range` call to the period of time you want an average for, you don’t need to use `aggregateWindow()` you can instead just you `mean()` on the entire set or results. That will guarantee that you get only one value per table.

You should also run `group(columns:["host"])` before your aggregate, so that it’s grouped according to what you want the aggregate for.

So, to summarize, try this:

```auto
from(bucket:"telegraf")
|> range(start:2022-05-30T02:21:46.000000000Z, stop:2022-05-30T02:22:46.000000000Z)
|> filter(fn: (r) => r["_measurement"] == "mem")
|> filter(fn: (r) => r["_field"] == "used_percent")
|> group(columns:["host"])
|> mean()
|> yield(name:"mean")

```
