# Counting occurrence of two events and then displaying the percentage

**URL:** https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040
**Category:** Kibana
**Created:** [August 7, 2017, 4:36am UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040 "2017-08-07T04:36:39Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Nikhil\_Utane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikhil_utane/32/27547_2.png) [@Nikhil\_Utane](https://discuss.elastic.co/u/Nikhil_Utane)
#### Post date: [August 7, 2017, 4:36am UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/1 "2017-08-07T04:36:39Z")

</div>

I got through many visualizations until I came across seemingly a very simple one. I am trying various options but I feel it should not be that complicated and I am missing a trick. My ask is simple, I have Request and Response events coming in from log file and I want to show a percentage of Responses to Requests (i.e. Count of Response/Count of Requests x 100).

I added a grok filter, to tag the request and responses messages. First I used the same field name with different values. But with this I couldn't quite even calculate the sum. Then I added an integer field with value 1 for every event so that I can use 'sum'. I am able to sum the values but still not able to calculate percentages. Even the scripted field doesn't help here since it always calculates as 100% (1/1 \* 100). Next I am looking at metrics filter and increment the counter through that. I should be able to achieve with this but it got me wondering whether I am making it too complex for my need. Please let me know if I am missing something here. Thanks.

---

<div class="post-metadata">

### Author: ![Stacey\_Gammon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stacey_gammon/32/14025_2.png) [@Stacey\_Gammon](https://discuss.elastic.co/u/Stacey_Gammon)
#### Post date: [August 7, 2017, 6:12pm UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/2 "2017-08-07T18:12:15Z")

</div>

The Time Series Visual Builder should be helpful here.

Here is some test data I have, to try and match your data:

 ![21 PM](https://us1.discourse-cdn.com/elastic/original/3X/8/3/8375cd0ca8aec60b3973065fa0461a544c699d13.png)

Here is my metric panel details in the Visual Builder.

 ![06 PM](https://us1.discourse-cdn.com/elastic/original/3X/1/b/1b5aa23ce7fa5afa1578542d91c6717391daa201.png)

I'm running into an issue at the moment ([https://github.com/elastic/kibana/issues/13370](https://github.com/elastic/kibana/issues/13370)) but I think this _should_ get you what you want.

---

<div class="post-metadata">

### Author: ![Nikhil\_Utane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikhil_utane/32/27547_2.png) [@Nikhil\_Utane](https://discuss.elastic.co/u/Nikhil_Utane)
#### Post date: [August 8, 2017, 3:27am UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/3 "2017-08-08T03:27:03Z")

</div>

Thank You Stacey for the detailed response. Yes with this I can now show the percentage as a time series. I also wanted to show a simple metric visualization with the latest percentage value as it stands.  
Is that possible?  
Right now I am displaying the sum, but I really want to show only the percentage.

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

Thanks.

---

<div class="post-metadata">

### Author: ![Nikhil\_Utane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikhil_utane/32/27547_2.png) [@Nikhil\_Utane](https://discuss.elastic.co/u/Nikhil_Utane)
#### Post date: [August 10, 2017, 5:38am UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/4 "2017-08-10T05:38:57Z")

</div>

Any comments? Thanks.

---

<div class="post-metadata">

### Author: ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)
#### Post date: [August 16, 2017, 7:30pm UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/5 "2017-08-16T19:30:05Z")

</div>

The Visual Builder has panels for Markdown and Gauge which can show a single metric. Maybe those would work for you?

Regards,  
Lee

---

<div class="post-metadata">

### Author: ![Stacey\_Gammon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stacey_gammon/32/14025_2.png) [@Stacey\_Gammon](https://discuss.elastic.co/u/Stacey_Gammon)
#### Post date: [August 16, 2017, 7:53pm UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/6 "2017-08-16T19:53:16Z")

</div>

So sorry for the lack of response @Nikhil_Utane.

I believe the answer is that it's not possible yet using the Time Series Visual Builder. See the response to my post in [[TSVB] Metric count shows 0 · Issue #13370 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/13370)

> That's a limitation of pipeline aggs, you can't use a sibling pipeline agg in a bucket\_script.

Which eliminates what I was trying to do with the Visual Builder metric.

In addition, you can't use scripted fields with the Visual Builder - [Scripted fields can not be used in Visual Builder · Issue #11999 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/11999)

so I don't think you can solve the issue that way either. So unfortunately, I don't think this is possible at the moment.

---

<div class="post-metadata">

### Author: ![Nikhil\_Utane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikhil_utane/32/27547_2.png) [@Nikhil\_Utane](https://discuss.elastic.co/u/Nikhil_Utane)
#### Post date: [August 17, 2017, 4:08am UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/7 "2017-08-17T04:08:29Z")

</div>

No problem Stacey.  
I don't HAVE TO use Visual Builder. As long as there is some way to perform some basic computation (percentage, min/max etc), it can be through Painless, Lucene whatever option is available. Thanks.

---

<div class="post-metadata">

### Author: ![Nikhil\_Utane](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nikhil_utane/32/27547_2.png) [@Nikhil\_Utane](https://discuss.elastic.co/u/Nikhil_Utane)
#### Post date: [August 18, 2017, 4:25am UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/8 "2017-08-18T04:25:47Z")

</div>

Please let me know if this cannot be accomplished even outside of visual builder. Thanks.

---

<div class="post-metadata">

### Author: ![LeeDr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leedr/32/9289_2.png) [@LeeDr](https://discuss.elastic.co/u/LeeDr)
#### Post date: [August 18, 2017, 5:09pm UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/9 "2017-08-18T17:09:17Z")

</div>

I don't think there's any other way right now in Kibana besides the Visual Builder to do some calculation like this and get just the metric.

The last post here shows using the `Overall Average` aggregation to get a single number for your whole timespan.

> [@Doing Math over count of events](https://discuss.elastic.co/t/doing-math-over-count-of-events/97278/20):
>
> Thanks for your patience. I'm learning more about Visual Builder as I go here... If you have your first aggregation which is a Filter Ratio which is calculating success/(success or failure). That ratio probably changes over time, and your gauge or markdown is showing the last value. But it sounds like you want a metric that shows the percentage over the entire timespan, which might be Last 15 minutes or Last 30 days. So you can add Overall Average aggregation to do that. First click the + …

---

<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: [September 15, 2017, 5:09pm UTC](https://discuss.elastic.co/t/counting-occurrence-of-two-events-and-then-displaying-the-percentage/96040/10 "2017-09-15T17:09:25Z")

</div>

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