# How can I calculate week of year for a heat map aggregation?

**URL:** <https://discuss.elastic.co/t/how-can-i-calculate-week-of-year-for-a-heat-map-aggregation/232035>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [May 11, 2020, 1:59pm UTC](https://discuss.elastic.co/t/how-can-i-calculate-week-of-year-for-a-heat-map-aggregation/232035 "2020-05-11T13:59:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hugo\_Pires](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hugo_pires/32/68069_2.png) [@Hugo\_Pires](https://discuss.elastic.co/u/Hugo_Pires)\
**Post date:** [May 11, 2020, 1:59pm UTC](https://discuss.elastic.co/t/how-can-i-calculate-week-of-year-for-a-heat-map-aggregation/232035/1 "2020-05-11T13:59:02Z")

</div>

Hello

I am using this painless code

```auto
(doc['time_start_ts'].value.dayOfYear - doc['time_start_ts'].value.dayOfWeek + 10) / 7;

```

to get a week\_of\_year scripted filed. My goal is to create a heatmap (with diferent years) with this field in the x axis.

So I will need to add year to the scripted field in order to differentiate the same week number from two different years.

Besides I will need to order properly the field, to get a time sorted heatmap. I would use calendar view, but I guess the plugin is not compatible with version 7.6

Thank you

Hugo

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [May 11, 2020, 5:42pm UTC](https://discuss.elastic.co/t/how-can-i-calculate-week-of-year-for-a-heat-map-aggregation/232035/2 "2020-05-11T17:42:13Z")

</div>

You can split the chart twice, once on Year and another one on Week. This way there shouldn't be any overlap on weeks from different years and you would have a different heatmap for each year.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 8, 2020, 5:42pm UTC](https://discuss.elastic.co/t/how-can-i-calculate-week-of-year-for-a-heat-map-aggregation/232035/3 "2020-06-08T17:42:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
