# Using Flux for retrieving montly data

**URL:** https://community.influxdata.com/t/using-flux-for-retrieving-montly-data/10662
**Category:** Telegraf
**Tags:** influxdb, flux
**Created:** [July 24, 2019, 9:12am UTC](https://community.influxdata.com/t/using-flux-for-retrieving-montly-data/10662 "2019-07-24T09:12:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Elisa\_Scheer](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/elisa_scheer/32/2725_2.png) [@Elisa\_Scheer](https://community.influxdata.com/u/Elisa_Scheer)
#### Post date: [July 24, 2019, 9:12am UTC](https://community.influxdata.com/t/using-flux-for-retrieving-montly-data/10662/1 "2019-07-24T09:12:12Z")

</div>

Hi all,

I am working with flux for retrieving my energy consumption dataset and grouping data by calendar month :

I wrote this request :

```
  from(bucket:"INFLUXDB-CLIENT/autogen") 
|> filter(fn : (r) => r._measurement == "Compteur Gaz" and r.tag_name == "Compteur")
|> range(start : 2019-07-01T00:00:00-00:00)
|> window(every : 1mo)
|> increase() 
|> last()

```

But as a result I expected one single result and I get 3 results :

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

Why it doesn’t show only a value for the period 01/07/19 to 24/07/19 ?

---

<div class="post-metadata">

### Author: ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)
#### Post date: [July 24, 2019, 8:41pm UTC](https://community.influxdata.com/t/using-flux-for-retrieving-montly-data/10662/2 "2019-07-24T20:41:03Z")

</div>

Hello @Elisa_Scheer,  
Thank you for your question. I’m having some trouble with window() right now as well. I need to ask someone, and I’ll get back to you. In the meantime, have you tired using [aggregateWindow()](https://github.com/influxdata/flux/blob/master/docs/SPEC.md#aggregateWindow)?

---

<div class="post-metadata">

### Author: ![Elisa\_Scheer](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/elisa_scheer/32/2725_2.png) [@Elisa\_Scheer](https://community.influxdata.com/u/Elisa_Scheer)
#### Post date: [July 25, 2019, 5:15am UTC](https://community.influxdata.com/t/using-flux-for-retrieving-montly-data/10662/3 "2019-07-25T05:15:02Z")

</div>

Hi,

Thanks for your reply, I tested aggregateWindow() :

```
 from(bucket:"INFLUXDB-CLIENT/autogen")
 |> filter(fn : (r) => r._measurement == "Compteur Gaz" and r.tag_name == "Compteur")
 |> range(start : 2019-06-01T00:00:00-00:00) 
 |> aggregateWindow(every : 1mo, fn : mean)

```

and this is the result :

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

and with the function window() :

```
from(bucket:"INFLUXDB-CLIENT/autogen") 
|> filter(fn : (r) => r._measurement == "Compteur Gaz" and r.tag_name == "Compteur") |> range(start : 2019-06-01T00:00:00-00:00) 
|> window(every : 1mo)
|> mean()

```

and here is the result :

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

I don’t understand why data are grouping from 2019-06-13 to 2019-07-11 and from 2019-07-11 to 2019-07-25 and not from 2019-06-13 to 2019-06-30 and from 2019-07-01 to 2019-07-25

Do you think it is because of the version of influxDB or something else?

Best regards

---

<div class="post-metadata">

### Author: ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)
#### Post date: [August 2, 2019, 8:11pm UTC](https://community.influxdata.com/t/using-flux-for-retrieving-montly-data/10662/4 "2019-08-02T20:11:04Z")

</div>

That is odd, I don’t understand it either. What do you get for

```auto
  |> range(start: dashboardTime)
  |> filter(fn: (r) => r._field == "usage_system")
  |> filter(fn: (r) => r.cpu == "cpu-total")
  |> aggregateWindow(every: 1mo, fn: mean)

```

?  
where dashboardTime is 06/01?

---

<div class="post-metadata">

### Author: ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)
#### Post date: [August 2, 2019, 8:11pm UTC](https://community.influxdata.com/t/using-flux-for-retrieving-montly-data/10662/5 "2019-08-02T20:11:30Z")

</div>

@Elisa_Scheer,  
What version of Influxdb are you using?
