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

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

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, this is on our roadmap and hopefully we are going to address it at a next minor.

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

1. Create a lens chart that will look like that

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

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

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