# \[URGENT\] Aggregate within window gives unexpected data points

**URL:** https://community.influxdata.com/t/urgent-aggregate-within-window-gives-unexpected-data-points/56852
**Category:** InfluxDB 2
**Tags:** flux
**Created:** [March 26, 2025, 8:31pm UTC](https://community.influxdata.com/t/urgent-aggregate-within-window-gives-unexpected-data-points/56852 "2025-03-26T20:31:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![airsence](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@airsence](https://community.influxdata.com/u/airsence)
#### Post date: [March 26, 2025, 8:31pm UTC](https://community.influxdata.com/t/urgent-aggregate-within-window-gives-unexpected-data-points/56852/1 "2025-03-26T20:31:10Z")

</div>

Hi,

We have been a customer of _ **InfluxDB Cloud v2** _ for a few years now and have been using it for air quality IoT.

We have encountered an issue with data aggregation that is affecting many of our customers; since we have ~1,000 devices, and customers check daily or monthly numbers, this adds up very quickly.

**What we’re trying to do**  
We want to get averages of data within a selected time window. E.g., a customer wants to see the 8-hour average of PM2.5 dust particles in the air collected from 8th March 2025 at 07:15 India Standard Time (IST) to 9th March 2025 at 07:15 IST.

**Expected results**  
We expect to see _ **3 data points** _ within the 24-hour period – one for each 8-hour window, namely:

1. 8th March 2025 at 15:15 IST
2. 8th March 2025 at 23:15 IST
3. 9th March 2025 at 07:15 IST

**Actual results**

We receive the following _ **4 data points** _:

1. 8th March 2025 at 10:30 IST
2. 8th March 2025 at 18:30 IST
3. 9th March 2025 at 02:30 IST
4. 9th March 2025 at 07:15 IST

**What we have tried so far**

We tried using the function `*timedMovingAverage(every: 8h, period: 8h)*` …

```auto
  import "timezone"
  option location = timezone.location(name: "Asia/Kolkata")

  from(bucket:"EVIN")
    |> range(start: 1741418100, stop: 1741504500)
    |> filter(fn: (r) => r._measurement == "Pollutant")
    |> filter(fn: (r) => r._field == "PM2_5")
    |> filter(fn: (r) => r.DeviceID == "AirSENCE-062409E640561")
    |> timedMovingAverage(every: 8h, period: 8h)
    |> yield()

```

Additionally, we have unsuccessfully tried to replace `timedMovingAverage` with:

```auto
    // Alternate #1 (2 variants - with and w/o timeSrc)
    |> aggregateWindow(every: 8h, fn: mean, createEmpty: false [, timeSrc: "_start"])

```

and with

```auto
    // Alternate #2
    |> window(every: 8h)
    |> reduce(fn: (r, accumulator) => ({<get average>}), identity: {count: 0.0, avg: 0.0} )

```

**However, none of these functions work as expected!**

**Could you please help us create an appropriate query to use a user-defined time window for aggregate operations?**

Regards,  
George

---

<div class="post-metadata">

### Author: ![airsence](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@airsence](https://community.influxdata.com/u/airsence)
#### Post date: [March 26, 2025, 8:34pm UTC](https://community.influxdata.com/t/urgent-aggregate-within-window-gives-unexpected-data-points/56852/2 "2025-03-26T20:34:24Z")

</div>

FYI: I’ve reviewed other community topics and tried to implement their suggested solutions, (e.g., using `timeShift`), most notably this topic:

> [@Unexpected timestamp when using aggregated window per day](https://community.influxdata.com/t/unexpected-timestamp-when-using-aggregated-window-per-day/26793):
>
> Hello, I am quite new to using InfluxDB (and also use Grafana in addition), but hereit is about pure InfluxDB behaviour. I am trying to query some data using Flux in the Data Explorer. I am working with an aggregated window and try to get the last value of a day. When setting the aggreation to 5s (seems to be the minimum), I have the individual values around the day change. If I now change the aggregation to 24h / 1d, I do get this: The values shown seem correct for me, but I woul…

---

<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: [March 31, 2025, 8:56pm UTC](https://community.influxdata.com/t/urgent-aggregate-within-window-gives-unexpected-data-points/56852/3 "2025-03-31T20:56:39Z")

</div>

Hello @airsence  
Did that work for you?  
How are you fairing now?

Ps I recommend checking out InfluxDB 3 Core and Enterprise Python Processing Engine it’s pretty cool.  
We’re just getting started but you’re able to quickly build so much especially paired with an LLM.

- [Transform Data with the New Python Processing Engine in InfluxDB 3](https://www.influxdata.com/blog/new-python-processing-engine-influxdb3/)
- [Get started: Python Plugins and the Processing Engine](https://docs.influxdata.com/influxdb3/enterprise/get-started/#python-plugins-and-the-processing-engine)
- [Processing engine and Python plugins](https://docs.influxdata.com/influxdb3/enterprise/plugins/)
- [Preventing Alert Storms with InfluxDB 3’s Processing Engine Cache](https://www.influxdata.com/blog/preventing-alert-storms-influxdb3/)
- [How to Set Up Real-Time SMS/WhatsApp Alerts with InfluxDB 3 Processing Engine](https://www.influxdata.com/blog/setting-up-sms-whatsapp-alerts-influxdb3/)
- [Alerting with InfluxDB 3 Core and Enterprise](https://www.influxdata.com/blog/core-enterprise-alerting-influxdb3/)
