# Dynamically binning timeseries data

**URL:** <https://community.amazonquick.com/t/dynamically-binning-timeseries-data/9851>\
**Category:** Q&A\
**Tags:** quick-sight\
**Created:** [February 9, 2023, 12:28am UTC](https://community.amazonquick.com/t/dynamically-binning-timeseries-data/9851 "2023-02-09T00:28:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![oek](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@oek](https://community.amazonquick.com/u/oek)\
**Post date:** [February 9, 2023, 12:28am UTC](https://community.amazonquick.com/t/dynamically-binning-timeseries-data/9851/1 "2023-02-09T00:28:22Z")

</div>

Hello,

I have some timeseries data that exceeds the 10,000 point limit for line charts. I need to display as much of the data as possible to give my customers as much context into the data as possible.

This data is partitioned from different “log files” that live in our database and its data rate is 1hz.

* * *

To make this data visible to consumers, I “bin” the data for each log file by time (e.g. apply an aggregation over a window). I “find the maximum for each data point in minute 1 and plot that, same for minute 2, etc”. This would result in 60 data points in each bin and can visualize up to a 166 minute log (10,000pts/60s).

I currently have a “binning parameter” that users can configure which defaults to 60s. This works; however, some of my log files are much longer or shorter than 166 minutes … So I would like to dynamically set bin based on the size of the log. It is very cumbersome and unprofessional to have to communicate to all my consumers: “see if there is a ‘other’ category in the legend of your plot, if so, decrease the bin size until it goes away” or “if the resolution looks too small, increase the bin size parameter until it looks better, but not too far”.

**Attempt 1** : Dynamically setting a Parameter default.  
I have a Parameter that controls everything set to 60s. If I could dynamically set that based on number of data points, then that would solve my issue. I dont see any way to do this.

**Attempt 2** : Build a calculated field for the bin size  
I have built up something to the effect of:

```auto
bin_size_s = lastValue(dataSet)-firstValue(dataSet) / 10000
timestamp_binned_s = decimalToInt({timestamp_s} / decimalToInt(bin_size_s)) * bin_size_s

```

I am able to visualize this in a table and confirm that the timestamp\_binned\_s is what I expect.

I can use timestamp\_binned\_s as my X axis and apply an aggregation for my Y data for the each…

However, Quick Sight says I cannot use a custom aggregation as a dimension field. This binning that im building must be a dimension field to be the X-axis in my line chart.

Does anyone have any suggestions or even different approaches to my high-level goal to “display my timeseries data with the 10,000 data point limitation”?

Thanks,  
Oliver

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [February 9, 2023, 9:49pm UTC](https://community.amazonquick.com/t/dynamically-binning-timeseries-data/9851/2 "2023-02-09T21:49:40Z")

</div>

For your first attempt you could look to set up a dynamic default. This would require you to create a separate dataset with your group number and all of the users that are logging in to set this dynamically.

> [@How to make Dynamic parameter](https://community.amazonquick.com/t/how-to-make-dynamic-parameter/3496/2):
>
> Hi, check out this it may help you slight_smile[[Filters in QuickSight] ](https://www.youtube.com/watch?v=ZeLHwG9IjT4)

For your second attempt can you instead do this in SQL?

---

<div class="post-metadata">

**Author:** ![oek](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@oek](https://community.amazonquick.com/u/oek)\
**Post date:** [February 9, 2023, 10:09pm UTC](https://community.amazonquick.com/t/dynamically-binning-timeseries-data/9851/3 "2023-02-09T22:09:39Z")

</div>

Thanks,

I was hoping to not have to touch my dataset at all.  
More context: I’m trying to do this for tens of dashboards which all have their own dataset. To create a new dataset or switch to SQL would mean I would have to build out support for programmatically doing this with the “Quick Sight definition API thing”. I currently generate all the dashboards programmatically but was hoping to not have to do the datasets.

While it sounds possible for your two suggestions, I was hoping not to 🙂 .

Do you understand the crux of the “custom aggregation cannot be a dimension”? That part left me pretty confused.

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [February 28, 2023, 9:26pm UTC](https://community.amazonquick.com/t/dynamically-binning-timeseries-data/9851/4 "2023-02-28T21:26:24Z")

</div>

Yes you can’t add aggregation as dimensions.

sum({field}) cannot be used as a group. Essentially this aggregation needs to be grouped itself and cannot be a group. The only have to make it a group is to transfer the logic to SQL so that it is already calculated and not aggregated in quicksight.

---

<div class="post-metadata">

**Author:** ![oek](https://avatars.discourse-cdn.com/v4/letter/o/f05b48/32.png) [@oek](https://community.amazonquick.com/u/oek)\
**Post date:** [March 1, 2023, 10:14pm UTC](https://community.amazonquick.com/t/dynamically-binning-timeseries-data/9851/5 "2023-03-01T22:14:27Z")

</div>

Understood. Thank you for the response
