# Is it possible to use aggregateWindow() with different functions?

**URL:** https://community.influxdata.com/t/is-it-possible-to-use-aggregatewindow-with-different-functions/23674
**Category:** InfluxDB 2
**Tags:** influxdb, query
**Created:** [February 3, 2022, 3:51pm UTC](https://community.influxdata.com/t/is-it-possible-to-use-aggregatewindow-with-different-functions/23674 "2022-02-03T15:51:49Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![amitrotner](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/amitrotner/32/9406_2.png) [@amitrotner](https://community.influxdata.com/u/amitrotner)
#### Post date: [February 3, 2022, 3:51pm UTC](https://community.influxdata.com/t/is-it-possible-to-use-aggregatewindow-with-different-functions/23674/1 "2022-02-03T15:51:49Z")

</div>

Hi,

Suppose I have a stock price data sampled every minute.

I’d like to aggregate the data in a 1 day window to a new bucket such that the fields in the new bucket will be defined in the following way:

1. Open - The first price in each window
2. Close - The last price in each window
3. High - The maximum price in each window
4. Low - The minimum price in each window

Of course I can iterate the data four times the calculate what I need but I guess it is not the most efficient way to do it.

Is it possible to use **one** `aggregateWindow()` function in order to achieve this goal?

Thanks

---

<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 3, 2022, 5:46pm UTC](https://community.influxdata.com/t/is-it-possible-to-use-aggregatewindow-with-different-functions/23674/2 "2022-02-03T17:46:19Z")

</div>

Hello @amitrotner,

The most efficient way to do this is with the following structure:

```auto
data = from() |> range() |> filter|>

open = data |> aggregateWindow(fn: first)
|> to()

close = data |> aggregateWindow(fn: last)
|> to()

high = data |> aggregateWindow(fn: max)
|> to()

low = data |> aggregateWindow(fn: min)
|> to()

```

However, aggwindow is a pushdown function. Pushdowns are functions **or function combinations that push data operations to the underlying data source** rather than operating on data in memory.  
So it’s possible that your approach is just as efficient. Id have to use the Flux profiler to verify:

> **[profiler package | Flux 0.x Documentation](https://docs.influxdata.com/flux/v0.x/stdlib/profiler/)**
>
> The profiler package provides performance profiling tools for Flux queries and operations.

> **[TL;DR InfluxDB Tech Tips Optimizing Flux Performance in InfluxDB Cloud](https://www.influxdata.com/blog/tldr-influxdb-tech-tips-optimizing-flux-performance-in-influxdb-cloud/)**
>
> Using InfluxDB Cloud and Flux? In this post, well learn about best practices and tools for optimizing Flux performance.

This way you don’t have to query for the data each time.  
No it’s not possible to use one aggregateWindow() function because data in flux is pipe-forwarded and aggWindow doesn’t support simultaneous outputs/multiple params for fn inputs.  
You could create a feature request though here: [GitHub - influxdata/flux: Flux is a lightweight scripting language for querying databases (like InfluxDB) and working with data. It's part of InfluxDB 1.7 and 2.0, but can be run independently of those.](https://github.com/influxdata/flux)
