# How to calculate minimum and maximun of Session duration

**URL:** <https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852>\
**Category:** Kibana\
**Created:** [February 1, 2021, 3:18pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852 "2021-02-01T15:18:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ITchandj](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@ITchandj](https://discuss.elastic.co/u/ITchandj)\
**Post date:** [February 1, 2021, 3:18pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852/1 "2021-02-01T15:18:03Z")

</div>

Hello everyone!!

i am new to Kibana and i lik to know how to calculate the minimum and maximum of a session. Thanks for your help.

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

---

<div class="post-metadata">

**Author:** ![afharo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afharo/32/75202_2.png) [@afharo](https://discuss.elastic.co/u/afharo)\
**Post date:** [February 1, 2021, 5:05pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852/2 "2021-02-01T17:05:02Z")

</div>

Hi @ITchandj,

Kibana provides "Max" and "Min" aggregations for that:

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

1. Simply go to Visualize \> Create new \> Data Table.
2. In the Buckets section add 1 date histogram (for "Last seen") and 3 Terms aggregations: 1 for the host, another one for the Hardware manufacturer, and the last one for Hardware model.
3. Then in the Metrics section, select the Aggregation "Min" and field "sessions", and repeat the process for Max and Top Hit (for Last).

---

<div class="post-metadata">

**Author:** ![ITchandj](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@ITchandj](https://discuss.elastic.co/u/ITchandj)\
**Post date:** [February 1, 2021, 5:35pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852/3 "2021-02-01T17:35:42Z")

</div>

thank you very much but i would like rather calculate the minimum and maximum duration of a session in kibana.  
for exemple the min and max of sessionlogonTime.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/4/141f8f8c4caf5ef505abfd5b906ba7f5f22885c0.png)

---

<div class="post-metadata">

**Author:** ![afharo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afharo/32/75202_2.png) [@afharo](https://discuss.elastic.co/u/afharo)\
**Post date:** [February 1, 2021, 5:45pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852/4 "2021-02-01T17:45:27Z")

</div>

Oh! So the `1` in the screenshot of the first comment is actually the number of seconds/minutes/hours of the session?

---

<div class="post-metadata">

**Author:** ![ITchandj](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@ITchandj](https://discuss.elastic.co/u/ITchandj)\
**Post date:** [February 1, 2021, 5:50pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852/5 "2021-02-01T17:50:31Z")

</div>

yes.. it is

---

<div class="post-metadata">

**Author:** ![afharo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afharo/32/75202_2.png) [@afharo](https://discuss.elastic.co/u/afharo)\
**Post date:** [February 1, 2021, 5:53pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852/6 "2021-02-01T17:53:32Z")

</div>

I'm struggling to understand how you get a duration out of 1 static date. Do you have any other field like SessionLogoutTime, so you can calculate the duration as `SessionLogoutTime - SessionLogonTime`?

---

<div class="post-metadata">

**Author:** ![ITchandj](https://avatars.discourse-cdn.com/v4/letter/i/f19dbf/32.png) [@ITchandj](https://discuss.elastic.co/u/ITchandj)\
**Post date:** [February 1, 2021, 5:58pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852/7 "2021-02-01T17:58:30Z")

</div>

No.. but i have field like SessionEndTime.  
but i how can calculate the minimum and the max

---

<div class="post-metadata">

**Author:** ![afharo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/afharo/32/75202_2.png) [@afharo](https://discuss.elastic.co/u/afharo)\
**Post date:** [February 1, 2021, 6:03pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852/8 "2021-02-01T18:03:37Z")

</div>

The Min and Max aggregations work for numbers and dates. So you can get the minimum SessionLogonTime in the same way I mentioned in my previous comment.

If you are after the duration, you might need to use a Runtime field or Kibana Scripted field that will execute `SessionEndTime - SessionLogonTime` and present it in another field in the document.

---

<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:** [March 1, 2021, 6:04pm UTC](https://discuss.elastic.co/t/how-to-calculate-minimum-and-maximun-of-session-duration/262852/9 "2021-03-01T18:04:05Z")

</div>

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