# Aggregate Startkey() & middlekey() Formula

## Recommended Posts

Hello,

I'm using the aggregate formula and I'm having hard time understanding Startkey() & middlekey().  Endkey() is very clear.

I used \$s.aggregate(average(),periods(1year,1day),Endkey()) to calculate the yearly rolling avg and time stamp it at the end of each day.

I did the same thing for 6 month capsules \$s.aggregate(average(),periods(1year,6month),Endkey()) and the end value of both data is equal.

When I use middlekey(): \$s.aggregate(average(),periods(1year,6month),middlekey()) , I thought Seeq would calculate the middle value of the capsule meaning  the last bar value on the graph below would calculate the average of 9/30/2018- 9/30/2019.

And for the startkey(), I thought the last bar value represents the beginning of the capsule rolling back 365 days.  from 6/30/2018- 6/30/2019.

##### Share on other sites

Hi Ali,

startKey(), middleKey() and endKey() provide just the timestamp where Seeq will put the calculated value. In your example using periods(1year,6month) Seeq will always calculate the average for one year starting from January (e.g. 01/01/2018 - 01/01/2019) and the average starting from July (e.g. 07/01/2018 - 07/01/2019).

For the period 01/01/2018 - 01/01/2019 using

- startKey() will put the value to 01/01/2018
- middleKey() will put the value to 07/01/2018
- endKey() will put the value to 01/01/2019

The marked columns in the following Analysis all have the same value for the period of last year :

Hope this helps.

Regards,

Thorsten

• 2

Thank you