# Can I use the values from the timepicker into aggregations?

**URL:** <https://discuss.elastic.co/t/can-i-use-the-values-from-the-timepicker-into-aggregations/317067>\
**Category:** Kibana\
**Created:** [October 20, 2022, 4:19am UTC](https://discuss.elastic.co/t/can-i-use-the-values-from-the-timepicker-into-aggregations/317067 "2022-10-20T04:19:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JimClark](https://avatars.discourse-cdn.com/v4/letter/j/cdc98d/32.png) [@JimClark](https://discuss.elastic.co/u/JimClark)\
**Post date:** [October 20, 2022, 4:19am UTC](https://discuss.elastic.co/t/can-i-use-the-values-from-the-timepicker-into-aggregations/317067/1 "2022-10-20T04:19:58Z")

</div>

My usecase is as follows:  
I have a network resource that I need to track the usage of.  
Every usage of the resource is recorded into a separate document with the total usage

@timestamp -\> End of usage  
@id -\> resource Id  
@usage\_duration -\> time in minutes

What I need is a visualization that shows the percentage of the network resource utilization compared to the time range chosen in the timepicker

Assuming the usage reconds

Oct 20, 2022 @ 00:00:00.981 - 1 - 480  
Oct 19, 2022 @ 00:00:00.981 - 1 - 720  
Oct 18, 2022 @ 00:00:00.981 - 1 - 420  
Oct 17, 2022 @ 00:00:00.981 - 1 - 720  
Oct 16, 2022 @ 00:00:00.981 - 1 - 360  
Oct 15, 2022 @ 00:00:00.981 - 1 - 900  
Oct 14, 2022 @ 00:00:00.981 - 1 -1440

Oct 20, 2022 @ 00:00:00.981 - 2 - 240  
Oct 19, 2022 @ 00:00:00.981 - 2 - 360  
Oct 18, 2022 @ 00:00:00.981 - 2 - 210  
Oct 17, 2022 @ 00:00:00.981 - 2 - 360  
Oct 16, 2022 @ 00:00:00.981 - 2 - 180  
Oct 15, 2022 @ 00:00:00.981 - 2 - 450  
Oct 14, 2022 @ 00:00:00.981 - 2 - 720

If I pick the resource Id on the x-axis and the percentage usage on the y-axis, I should be able to see the Percentage of usage of the resource for the time range that is picked in the timepicker

Ex: If the timepicker has the range Oct 14, 2022 @ 00:00:00.981 to Oct 20, 2022 @ 00:00:00.981, then it should show the 50% for Id 1 and 25% for Id 2  
Sum(@duration) in this case will be 5040 and 2520 for Id 1 and Id 2 respectively. Dividing with the number of minutes in the time range (7 days = 7 \* 24 \* 60 = 10080), the percentages are 50 and 25 respectively

Similarly, If the timepicker has the range Oct 7, 2022 @ 00:00:00.981 to Oct 20, 2022 @ 00:00:00.981, then it should show the 25% for Id 1 and 12.5% for Id 2  
Sum(@duration) in this case will be 5040 and 2520 for Id 1 and Id 2 respectively. Dividing with the number of minutes in the time range (14 days = 14 \* 24 \* 60 = 20160), the percentages are 25 and 12.5 respectively

---

<div class="post-metadata">

**Author:** ![Stratoula\_Kalafateli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stratoula_kalafateli/32/70923_2.png) [@Stratoula\_Kalafateli](https://discuss.elastic.co/u/Stratoula_Kalafateli)\
**Post date:** [October 20, 2022, 6:14am UTC](https://discuss.elastic.co/t/can-i-use-the-values-from-the-timepicker-into-aggregations/317067/2 "2022-10-20T06:14:15Z")

</div>

Hey! Unfortunately this is not supported atm but we have a feature request for that in the Lens editor. Check the issue here [[Lens] Formula: Date math · Issue #112851 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/112851), this is on our roadmap and hopefully we are going to address it at a next minor.

---

<div class="post-metadata">

**Author:** ![Stratoula\_Kalafateli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stratoula_kalafateli/32/70923_2.png) [@Stratoula\_Kalafateli](https://discuss.elastic.co/u/Stratoula_Kalafateli)\
**Post date:** [October 20, 2022, 12:19pm UTC](https://discuss.elastic.co/t/can-i-use-the-values-from-the-timepicker-into-aggregations/317067/3 "2022-10-20T12:19:47Z")

</div>

So, we actually looked into it with @Marco_Liberati and you can do it with a runtime field for now.

1. Go to your dataview management page and add a new field. I created a double timestamp\_ms field that returns your timestamp in ms

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/c/5c572fe4cda3a6c4d89107a99eb9115ea849811d.png)

1. Create a lens chart that will look like that  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/c/9c85d21f52203689d6fb930564ad5fd2b1d3da5f.png)

I am using formula on the vertical axis with a percent format

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/f/5/f5eb5890f048b701223ee97079e6eb1ab4986197.png)

With adding date math on our formula (the issue I posted before) we are going to make it easier to use as you won't need to create a runtime field 🙂

---

<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:** [November 17, 2022, 12:19pm UTC](https://discuss.elastic.co/t/can-i-use-the-values-from-the-timepicker-into-aggregations/317067/4 "2022-11-17T12:19:48Z")

</div>

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