# Monthly aggregateWindow always cuts off at 30th

**URL:** <https://community.grafana.com/t/monthly-aggregatewindow-always-cuts-off-at-30th/139386>\
**Category:** InfluxDB\
**Created:** [January 1, 2025, 2:33pm UTC](https://community.grafana.com/t/monthly-aggregatewindow-always-cuts-off-at-30th/139386 "2025-01-01T14:33:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![soeryobadja](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@soeryobadja](https://community.grafana.com/u/soeryobadja)\
**Post date:** [January 1, 2025, 2:33pm UTC](https://community.grafana.com/t/monthly-aggregatewindow-always-cuts-off-at-30th/139386/1 "2025-01-01T14:33:59Z")

</div>

Hi all,

I am using Grafana 10.2.2 with Influxdb v2.7.8 to monitor my energy consumption and display monthly usage. I can say it is working, but only one problem: the monthly cutoff date is always on 30th even though the raw data provides until 31st. Here is one example.

 ![Screen Shot 2025-01-01 at 21.26.56](https://us1.discourse-cdn.com/grafana/original/3X/3/d/3db7c2c739a77940cbce99952630d18f826711a5.png)  
Cutoff date for month December ends at 30th of December, similar thing happened to month of October.  
 ![Screen Shot 2025-01-01 at 21.28.04](https://us1.discourse-cdn.com/grafana/original/3X/1/f/1fe2b78eae44f57e23b44a27bd42183cd065c56e.png)

Here is the code I put inside Grafana

```auto
option location = {zone: "", offset: 1s}

from(bucket: "gupbdg-powermon")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["entity_id"] == "monthly_total_energy")
  |> filter(fn: (r) => r["domain"] == "sensor")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["_measurement"] == "kWh")
  |> aggregateWindow(every: 1mo, fn: last, createEmpty: false)
  |> yield(name: "last")

```

Here is the screenshot of the raw data.

 ![Screen Shot 2025-01-01 at 21.30.42](https://us1.discourse-cdn.com/grafana/original/3X/d/b/db9f05cc89dcf47793de8b437fb69e5f7a62312d.png)

I am expecting that, a monthly aggregateWindow function provides end of month cutoff date according the the number of days each month, be it 30, 31 or 28 in February. But why my configuration always cuts off at 30th every month?

Any help to sort this problem is very much appreciated. Thank you in advance.

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [January 1, 2025, 2:57pm UTC](https://community.grafana.com/t/monthly-aggregatewindow-always-cuts-off-at-30th/139386/2 "2025-01-01T14:57:19Z")

</div>

What does the data look like when you run it inside infludb… Does it work there

---

<div class="post-metadata">

**Author:** ![soeryobadja](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@soeryobadja](https://community.grafana.com/u/soeryobadja)\
**Post date:** [January 6, 2025, 2:03pm UTC](https://community.grafana.com/t/monthly-aggregatewindow-always-cuts-off-at-30th/139386/3 "2025-01-06T14:03:58Z")

</div>

I am using a template sensor in Home Assistant to monitor monthly electricity consumption. The sensor worked properly by providing measurement up until 31 Dec 2024 23.59.59 (similar case on October whereby raw data at Home Assistant Template Sensor cuts off at 31 Oct 2024 23.59.59) and the Influxdb shows the same (meaning, last timestamtp data was at 31 Dec 2024 at 23.59.59). That’s why I dont’t understand why Grafana cuts off at 30th every month, even though actually the month should have cut off at 31.

---

<div class="post-metadata">

**Author:** ![grant2](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/grant2/32/42281_2.png) [@grant2](https://community.grafana.com/u/grant2)\
**Post date:** [January 7, 2025, 11:19am UTC](https://community.grafana.com/t/monthly-aggregatewindow-always-cuts-off-at-30th/139386/4 "2025-01-07T11:19:44Z")

</div>

Just for kicks, can you replace your aggregateWindow line with this one and see how it affects your query results?  
`|> aggregateWindow(every: 1mo, offset: 1d, fn: last, timeSrc:"_start")`  
You might also see how adding `createEmpty: true` affects the results.

---

<div class="post-metadata">

**Author:** ![soeryobadja](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@soeryobadja](https://community.grafana.com/u/soeryobadja)\
**Post date:** [January 31, 2025, 3:08pm UTC](https://community.grafana.com/t/monthly-aggregatewindow-always-cuts-off-at-30th/139386/5 "2025-01-31T15:08:45Z")

</div>

Hi,  
Just applying the update and the result as follow:

1. Applying `createEmpty = true` showed up the previous months where the data is not yet available, so this view is not suitable, at least aesthetically.
2. Applying `aggregateWindow(every: 1mo, offset: 1d, fn: last, createEmpty: false)` results in the following graph (a small portion of the usage of 1st date is separated, yet the total usage of past month (December) still ends at 30th, 23:59:59).  
 ![Screen Shot 2025-01-31 at 22.03.55](https://us1.discourse-cdn.com/grafana/original/3X/0/a/0a7a2bdd6126c3fd22d0650589682d707f30e728.png)  
As you can see, for this month, it still shows up until 31/01, writing this at 22:06 my local time.
3. Adding `timeSrc:"_start"` results in No Data.

Something is not right here. Very curious about this.

---

<div class="post-metadata">

**Author:** ![soeryobadja](https://avatars.discourse-cdn.com/v4/letter/s/8e8cbc/32.png) [@soeryobadja](https://community.grafana.com/u/soeryobadja)\
**Post date:** [January 31, 2025, 3:22pm UTC](https://community.grafana.com/t/monthly-aggregatewindow-always-cuts-off-at-30th/139386/6 "2025-01-31T15:22:27Z")

</div>

OK, I made some mistake here.  
Here is additional explanation:

1. I have 6 measurement (1-6 in the legend of the graph), each are built using template from Home Assistant.
2. I build up the stack table by creating 6 data queries as follow.  
 ![Screen Shot 2025-01-31 at 22.15.50](https://us1.discourse-cdn.com/grafana/original/3X/5/6/56ac50d8b05a4f7be2fcd0897a5933ce4f8f860c.png)
3. I changed the query as proposed, `aggregateWindow(every: 1mo, offset: 1d, fn: last, createEmpty: false)` to all 6 queries, and the resulting graph shows like this (full month of December no longer showing, only shows 01-Dec-24, and 01-Jan-25 is separated from the rest of this mont, still showing up to 31-Jan-25 at 22.18 my local time):  
 ![Screen Shot 2025-01-31 at 22.18.52](https://us1.discourse-cdn.com/grafana/original/3X/6/5/6571a8e31c9df4bea8285e4612048d73d4a2c525.png)

Each of my queries are as follow:

```auto
option location = {zone: "", offset: 1s}

from(bucket: "gupbdg-powermon")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["entity_id"] == "monthly_energy_1_office")
  |> filter(fn: (r) => r["_field"] == "value")
  |> filter(fn: (r) => r["_measurement"] == "kWh")
  |> filter(fn: (r) => r["domain"] == "sensor")
  |> aggregateWindow(every: 1mo, offset: 1d, fn: last, createEmpty: false)
  |> yield(name: "last")

```

Intresting to see how the graph will change in the middle of the night.

Appreciate very much on any solution for this situation.
