# Timestamp with aggregatewindow function

**URL:** https://community.influxdata.com/t/timestamp-with-aggregatewindow-function/33072
**Category:** Fluxlang
**Created:** [February 2, 2024, 9:01pm UTC](https://community.influxdata.com/t/timestamp-with-aggregatewindow-function/33072 "2024-02-02T21:01:57Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![user642](https://avatars.discourse-cdn.com/v4/letter/u/cab0a1/32.png) [@user642](https://community.influxdata.com/u/user642)
#### Post date: [February 2, 2024, 9:01pm UTC](https://community.influxdata.com/t/timestamp-with-aggregatewindow-function/33072/1 "2024-02-02T21:01:57Z")

</div>

I want to have the average temperature per day. But when i use the aggregation function it sets the timestamp at the end.  
I dont understand why. The average temp of a day with timestamp at 0:00 at the next day doesnt seem to make any sense to me. Wouldnt it be better to have the timestamp at 12:00 because thats the middle of the day?

how do i know where the data comes from later? In my opition i need 2 timestamps. One for the beginning and one for the end.

Or do i have later to shift my axis by -12h to have the point in grafana at the middle of the day?

---

<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: [February 2, 2024, 10:01pm UTC](https://community.influxdata.com/t/timestamp-with-aggregatewindow-function/33072/2 "2024-02-02T22:01:43Z")

</div>

Hello @user642 Welcome!  
Deciding how to bound windows of time is always challenging in the space and there are pros and cons to each.  
Some people want a window defined by the start of the day 00:00 others want 24:00 but others also don’t like 24:00 because its techinically in the next day so they really want 23:59. You want 12:00. Every use case is different. I like your idea of having bounds.

the window() funciton gives you start and stop window times

> **[window() function | Flux Documentation](https://docs.influxdata.com/flux/v0/stdlib/universe/window/#Copyright)**
>
> window() groups records using regular time intervals.

If you query your data from the start of a day and then window() youll get start and stop columns that reflect those window start and stop times.

then you can use an empty |\> group() to put all of those windows into one table if you need 🙂

I hope that helps.

---

<div class="post-metadata">

### Author: ![Francis](https://avatars.discourse-cdn.com/v4/letter/f/ac8455/32.png) [@Francis](https://community.influxdata.com/u/Francis)
#### Post date: [May 30, 2024, 11:30am UTC](https://community.influxdata.com/t/timestamp-with-aggregatewindow-function/33072/3 "2024-05-30T11:30:28Z")

</div>

I have the same concern as @user642, and I find that the provided link to the window() function does not answer the question. How would I go about getting the queried values to have a timestamp equal to the _start_ of the aggregate window?

For context, I’ve provided the image below that shows a chart with data at irregular intervals (dots), the _expected_ values at a fixed-interval query with interpolation between points, and the results of the query that I’ve been able to cobble together in _Flux_. The queried points are offset by 5s (the duration of the aggregate window) when compared to the expected values.

 ![Screenshot 2024-05-30 072829](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/f/f5f76afbcab398cfe7e98f4bb4264fc1a6fe327e.png)

---

<div class="post-metadata">

### Author: ![Francis](https://avatars.discourse-cdn.com/v4/letter/f/ac8455/32.png) [@Francis](https://community.influxdata.com/u/Francis)
#### Post date: [May 31, 2024, 4:04pm UTC](https://community.influxdata.com/t/timestamp-with-aggregatewindow-function/33072/4 "2024-05-31T16:04:02Z")

</div>

To answer my own question, this is doable with the timeShift function:

 ![Screenshot 2024-05-31 120338](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/3/36f05682ae2c2c84171529fd39f38fc37b75f088.png)

---

<div class="post-metadata">

### Author: ![scott](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/scott/32/16492_2.png) [@scott](https://community.influxdata.com/u/scott)
#### Post date: [June 5, 2024, 3:55pm UTC](https://community.influxdata.com/t/timestamp-with-aggregatewindow-function/33072/5 "2024-06-05T15:55:11Z")

</div>

@Francis There’s a simpler answer to your problem. `aggregateWindow()` includes a `timeSrc` parameter that lets you specify the column to use for the output timestamps. By default, this is `_stop`. You can set it to `_start` to using the starting boundary of each window as the output timestamp:

```javascript
//...
    |> aggregateWindow(every: 5s, fn: first, createEmpty: false, timeSrc: "_start")

```

No need to use `timeShift()` after `aggregateWindow()`.
