# How do I downsample data using multiple operations within the same bucket (in Influxdb 2.0)?

**URL:** <https://community.influxdata.com/t/how-do-i-downsample-data-using-multiple-operations-within-the-same-bucket-in-influxdb-2-0/16042>\
**Category:** Systems\
**Created:** [September 21, 2020, 6:19am UTC](https://community.influxdata.com/t/how-do-i-downsample-data-using-multiple-operations-within-the-same-bucket-in-influxdb-2-0/16042 "2020-09-21T06:19:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zane470](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/zane470/32/5642_2.png) [@Zane470](https://community.influxdata.com/u/Zane470)\
**Post date:** [September 21, 2020, 6:19am UTC](https://community.influxdata.com/t/how-do-i-downsample-data-using-multiple-operations-within-the-same-bucket-in-influxdb-2-0/16042/1 "2020-09-21T06:19:22Z")

</div>

So I want to downsample my data by taking the min, max and mean of the data every hour and storing it in a bucket. I’m following the below link, which works for one operation, but not all three.

> **[Downsample data in an InfluxDB task | InfluxDB OSS 2.6 Documentation](https://docs.influxdata.com/influxdb/v2.0/process-data/common-tasks/downsample-data/)**
>
> How to create a task that downsamples data much like continuous queries in previous versions of InfluxDB.

The issue is that when using the method in the link, all of the measurement names are exactly the same in the output. I instead need the new measurement names to be “temperature\_mean”, “temperature\_min”, “temperature\_max” etc. Or I guess the measurements can be named the same thing, just “temperature” but then they need a mean tag, a min tag and a max tag. I can’t figure out how to do this.

I’ve tried using from(), to(), aggregateWindow(), rename()…nothing I do seems to work.

---

<div class="post-metadata">

**Author:** ![Zane470](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/zane470/32/5642_2.png) [@Zane470](https://community.influxdata.com/u/Zane470)\
**Post date:** [September 21, 2020, 11:05pm UTC](https://community.influxdata.com/t/how-do-i-downsample-data-using-multiple-operations-within-the-same-bucket-in-influxdb-2-0/16042/2 "2020-09-21T23:05:39Z")

</div>

Just to summarize:

```
option task = {name: "downsample_task", every: 1h}

data = from(bucket: "some_bucket")
	|> range(start: -duration(v: int(v: task.every) * 2))
	|> filter(fn: (r) =>
		(r["_measurement"] == "some_data" or r["_measurement"] == "some_other_data"))

data
	|> aggregateWindow(fn: mean, every: 1h)
	|> to(bucket: "some_bucket_downsampled", org: "anemail@gmail.com")

```

The above code does work – it calculates the mean every 1 hour and puts it into a new bucket. The issue is that I also want to get the min and max and put it in the same bucket. How do I do this? The main problem I’m facing is that the output isn’t prefixed or postfixed with \_mean, so every downsampled measurement has the same name.

---

<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:** [September 23, 2020, 5:23pm UTC](https://community.influxdata.com/t/how-do-i-downsample-data-using-multiple-operations-within-the-same-bucket-in-influxdb-2-0/16042/3 "2020-09-23T17:23:52Z")

</div>

Hello @Zane470,  
You can specifying the measurement in the to() function. You would just need to write dummy data to that bucket first to initialize the measurement. You can construct a table and write it to the bucket first after adding a measurement.

> **[TL;DR Tech Tips — How to Construct a Table with Flux](https://www.influxdata.com/blog/tldr-tech-tips-how-to-construct-a-table-with-flux/)**
>
> In this post, we share how to use the array.from() function to construct a table from an array of records with Flux.

Then you can write the outputs do those measurements:

```auto
|> to(bucket: "some_bucket_downsampled", _measurement: "mean")

```

Alternatively you can create a task for each downsampled aggregation.

Also, please check out these resources as well:

> [@Multiple Aggregation Projections in fluxql](https://community.influxdata.com/t/multiple-aggregation-projections-in-fluxql/15278/3):
>
> There are a few things they could do. Union and pivot two streams: |\> range(start: -1d) |\> filter(fn: (r) =\> r.\_field == "temp") temp\_mean = data |\> mean() |\> set(key: "\_field", as: "temp\_mean") num\_points = data |\> count |\> set(key: "\_field", as: "num\_points") union(tables: [temp\_mean, num\_points]) |\> pivot(rowKey:["\_time"], columnKey: ["\_field"], valueColumn: "\_value") Use reduce to create a custom aggregate that does both at the same time: data = from(bucket: "example-bucket") |\> …

> **[How to Extract Values & Visualize Scalars with Flux and InfluxDB](https://www.influxdata.com/blog/tldr-tech-tips-how-to-extract-values-visualize-scalars-and-perform-custom-aggregations-with-flux-and-influxdb/)**
>
> In this post, we learn how to use the reduce(), findColumn(), and findRecord() Flux functions to perform custom aggregations with InfluxDB.
