content/shared/influxdb-v2/tools/notebooks/downsample.md
Create a notebook to downsample data. Downsampling aggregates or summarizes data within specified time intervals, reducing the overall disk usage as data collects over time.
The following example creates a notebook that queries Coinbase bitcoin price sample data from the last hour, downsamples the data into ten minute summaries, and then writes the downsampled data to an InfluxDB bucket.
If you do not have an existing bucket to write the downsampled data to, create a new bucket.
Select Past 1h from the time range drop-down list at the top of your notebook.
In the Build a Query cell:
Click {{% icon "notebook-add-cell" %}} after your Build a Query cell to add a new cell and select {{% caps %}}Flux Script{{% /caps %}}.
In the Flux script cell:
Use __PREVIOUS_RESULT__ to load the output of the previous notebook
cell into the Flux script.
Use aggregateWindow()
to window data into ten minute intervals and return the average of each interval.
Specify the following parameters:
{{% show-in "cloud,cloud-serverless" %}}
3. Use to()
to write the downsampled data back to an InfluxDB bucket.
{{% /show-in %}}
__PREVIOUS_RESULT__
|> aggregateWindow(every: 10m, fn: mean)
|> to(bucket: "example-bucket")
{{% show-in "v2" %}} 7. Click {{% icon "notebook-add-cell" %}} after your Flux Script cell to add a new cell and select {{% caps %}}Output to Bucket{{% /caps %}}. Select a bucket from the {{% icon "bucket" %}} Choose a bucket drop-down list. {{% /show-in %}}
To continuously run your notebook, export the notebook as a task:
Click {{% icon "notebook-add-cell" %}} to add a new cell, and then select {{% caps %}}Task{{% /caps %}}.
Provide the following:
Click {{% icon "export" %}} Export as Task.