# Populating a Kibana Table with formula

**URL:** <https://discuss.elastic.co/t/populating-a-kibana-table-with-formula/126935>\
**Category:** Kibana\
**Created:** [April 5, 2018, 1:15pm UTC](https://discuss.elastic.co/t/populating-a-kibana-table-with-formula/126935 "2018-04-05T13:15:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oskar\_Myrberg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/oskar_myrberg/32/29623_2.png) [@Oskar\_Myrberg](https://discuss.elastic.co/u/Oskar_Myrberg)\
**Post date:** [April 5, 2018, 1:15pm UTC](https://discuss.elastic.co/t/populating-a-kibana-table-with-formula/126935/1 "2018-04-05T13:15:35Z")

</div>

Hi everyone! I searched around on the forum but couldn't find any answer to this question.

I have this data in Kibana:  
"startTime": "2018-03-14T15:05:13",  
"stopTime": "2018-03-14T15:02:27"

and I created a scripted field that is stopTime minus startTime called Downtime.

Now I want to get an output that calculates availability during one month, e.g. march. The formula would be (downtime/Total\_time\_in\_march) filtered on March.

I can't see how I can acheive this, any hints?

---

<div class="post-metadata">

**Author:** ![Bargs](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bargs/32/5429_2.png) [@Bargs](https://discuss.elastic.co/u/Bargs)\
**Post date:** [April 6, 2018, 7:03pm UTC](https://discuss.elastic.co/t/populating-a-kibana-table-with-formula/126935/2 "2018-04-06T19:03:27Z")

</div>

I haven't used the newer Java date time api in anger much so there may be a more elegant way to do this, but here's how I'd try to approach the problem.

- If you're already calculating `downtime`, you probably have a `LocalDateTime` or `ZonedDateTime` object for `startTime` and `stopTime`.
- You can use the [with](https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#with-java.time.temporal.TemporalAdjuster-) method on one of those objects, along with the helpers provided in [TemporalAdjusters](https://docs.oracle.com/javase/8/docs/api/java/time/temporal/TemporalAdjusters.html), to get DateTimes representing the first day of the current month and the next month.
- Make sure to [truncate](https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html#truncatedTo-java.time.temporal.TemporalUnit-) these to DAYS, or you might even be able to use a LocalDate instead of a LocalDateTime. Depends which will work in the next step, I'm not sure off the top of my head.
- Create a [duration](https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#between-java.time.temporal.Temporal-java.time.temporal.Temporal-) object with these two dates. Note the end of the range is exclusive, which is what we want.
- Get the [millis](https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#toMillis--) from the Duration, this represents the number of millis in the current month.
- Use these millis in your availability formula

---

<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:** [May 4, 2018, 7:03pm UTC](https://discuss.elastic.co/t/populating-a-kibana-table-with-formula/126935/3 "2018-05-04T19:03:27Z")

</div>

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