# Convert seconds into minutes after sum aggregation

**URL:** <https://discuss.elastic.co/t/convert-seconds-into-minutes-after-sum-aggregation/261927>\
**Category:** Kibana\
**Created:** [January 22, 2021, 2:38pm UTC](https://discuss.elastic.co/t/convert-seconds-into-minutes-after-sum-aggregation/261927 "2021-01-22T14:38:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![albie.morken](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/albie.morken/32/77563_2.png) [@albie.morken](https://discuss.elastic.co/u/albie.morken)\
**Post date:** [January 22, 2021, 2:38pm UTC](https://discuss.elastic.co/t/convert-seconds-into-minutes-after-sum-aggregation/261927/1 "2021-01-22T14:38:33Z")

</div>

I have an es index which contains the documents to indicate the time spent in seconds by an user in an activity like the one below

> ```
> {
> "UserName" : "User1",
> "Activity" : "Interacting",
> "TimeSpent" : 50
> }
> 
> ```

I need to visualize the total time spent by each user in every activity. I am able to create the chart with the sum and term aggregation.

But I have a requirement to show the time spent in minutes instead of seconds (Y- axis). I tried to convert the data before aggregation by using a scripted field. But the data is lost when trying to convert seconds to minutes(50 seconds converted to 0 minutes).

I need to find a way where I can sum all the seconds of time spent and then convert it into minutes. Is there a way I can achieve this ?

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [January 22, 2021, 2:58pm UTC](https://discuss.elastic.co/t/convert-seconds-into-minutes-after-sum-aggregation/261927/2 "2021-01-22T14:58:37Z")

</div>

use a tsvb visulization in kibana. and do as below. field name will be different for you. but you can divide the number /60 get you minute

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/0/80b873eb31df7864298a67bae232739b842bd7d8.png)

another way you can do is to go to index pattern and convert that field to duration and kibana will display accordingly. here is example my cpu\_minutes is your TimeSpent

![image](https://us1.discourse-cdn.com/elastic/original/3X/2/0/20df1cb9c184a177683edeccad50760218cee5cd.png)

---

<div class="post-metadata">

**Author:** ![albie.morken](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/albie.morken/32/77563_2.png) [@albie.morken](https://discuss.elastic.co/u/albie.morken)\
**Post date:** [January 25, 2021, 4:24am UTC](https://discuss.elastic.co/t/convert-seconds-into-minutes-after-sum-aggregation/261927/3 "2021-01-25T04:24:07Z")

</div>

Thanks ! I was able to convert the TimeSpent into minutes with both the options. But I want to show the stacked bar graph with TimeSpent in y axis and username/activity in X axis. I couldn't achieve this with Time Series. The second option was almost closer, but the only issue is that the TimeSpent minutes in Y axis are shown in decimal scale. Is there a way to have it in whole number of minutes ?

![image](https://us1.discourse-cdn.com/elastic/original/3X/8/0/80a1d3674dacc204f696ff720abdf3ef459d17bf.png)

---

<div class="post-metadata">

**Author:** ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)\
**Post date:** [January 25, 2021, 2:42pm UTC](https://discuss.elastic.co/t/convert-seconds-into-minutes-after-sum-aggregation/261927/4 "2021-01-25T14:42:08Z")

</div>

> [@albie.morken](#):
>
> minutes in Y axis are shown in decimal scale

you can combine with some tinymath function. I think ceil is what you looking

[https://www.elastic.co/guide/en/kibana/master/canvas-tinymath-functions.html#\_ceil\_a](https://www.elastic.co/guide/en/kibana/master/canvas-tinymath-functions.html#_ceil_a)

---

<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:** [February 22, 2021, 2:42pm UTC](https://discuss.elastic.co/t/convert-seconds-into-minutes-after-sum-aggregation/261927/5 "2021-02-22T14:42:12Z")

</div>

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