# Kibana: Unable to calculate average

**URL:** <https://discuss.elastic.co/t/kibana-unable-to-calculate-average/300847>\
**Category:** Kibana\
**Created:** [March 28, 2022, 1:23pm UTC](https://discuss.elastic.co/t/kibana-unable-to-calculate-average/300847 "2022-03-28T13:23:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sravanreddy.t](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@sravanreddy.t](https://discuss.elastic.co/u/sravanreddy.t)\
**Post date:** [March 28, 2022, 1:23pm UTC](https://discuss.elastic.co/t/kibana-unable-to-calculate-average/300847/1 "2022-03-28T13:23:28Z")

</div>

Hi, Need your help to calculate the average for the test cases.  
For Ex:  
No of test cases executed: 0,0,1,2  
Total Builds : 4  
My requirement is to calculate the average only for the no of test cases are more than zero. Otherwise the average count will be calculated for total builds : 4, it suppose to consider only 2. Please suggest me the solution in Kibana dashboard.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 29, 2022, 8:36am UTC](https://discuss.elastic.co/t/kibana-unable-to-calculate-average/300847/2 "2022-03-29T08:36:31Z")

</div>

It's not 100% clear from you question, how do the documents look like you want to visualize? Are the "number of test cases" part of an array field in a single documents, or are there multiple documents?

---

<div class="post-metadata">

**Author:** ![sravanreddy.t](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@sravanreddy.t](https://discuss.elastic.co/u/sravanreddy.t)\
**Post date:** [March 30, 2022, 4:57am UTC](https://discuss.elastic.co/t/kibana-unable-to-calculate-average/300847/3 "2022-03-30T04:57:16Z")

</div>

Yes. How can I visualize the documents in the Kibana dashboard.  
There will be one document for each build and it corresponding test cases.

For Example: Please find the step wise explanation for better understanding

1. We don't have test cases implemented in the application and data is populated in the Kibana. Build No : 1 and 2 in the above example.
2. After 2 successful builds, developer implemented the test cases and run the build (Build No: 3 and 4) and successfully published the test results into the Kibana.
3. How average will be calculated in this case --\> The formula is = Total no. of test cases/ Total Builds?
4. But my expectation is it should skip Build no 1 & 2 and only consider the build 3 &4. Because test cases are not implemented for 1 &2.

No of test cases executed: 0,0,1,2  
Total Builds : 4  
Average = (0+0+1+2)/4 = 0.75  
But my expectation is : (1+2)/2 = 1.5

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 30, 2022, 10:37am UTC](https://discuss.elastic.co/t/kibana-unable-to-calculate-average/300847/4 "2022-03-30T10:37:01Z")

</div>

So your documents look like this?

```auto
{ testCases: 0, buildNr: 1 }
{ testCases: 0, buildNr: 2 }
{ testCases: 1, buildNr: 3 }
{ testCases: 2, buildNr: 4 }

```

If yes, then you can get the average you are looking for by doing an "average of testCases", then adding the following filter in the KQL bar at the top: `testCases > 0`

---

<div class="post-metadata">

**Author:** ![sravanreddy.t](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@sravanreddy.t](https://discuss.elastic.co/u/sravanreddy.t)\
**Post date:** [March 30, 2022, 12:20pm UTC](https://discuss.elastic.co/t/kibana-unable-to-calculate-average/300847/5 "2022-03-30T12:20:43Z")

</div>

This is working for only if we want to display the unit test cases. But our requirement is to populate the total builds information and average test case information in the same dashboard. Hence missing the some of the builds information (Unit test cases count zero) in the dashboard. Because it exclude the Unit test cases are zero records.

---

<div class="post-metadata">

**Author:** ![flash1293](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/flash1293/32/41227_2.png) [@flash1293](https://discuss.elastic.co/u/flash1293)\
**Post date:** [March 31, 2022, 12:41pm UTC](https://discuss.elastic.co/t/kibana-unable-to-calculate-average/300847/6 "2022-03-31T12:41:14Z")

</div>

I see, I think using Lens formula could help you:

```auto
sum(testCases) / count(kql="testCases > 0")

```

It won't affect other dimension in the same chart.

---

<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:** [April 28, 2022, 12:42pm UTC](https://discuss.elastic.co/t/kibana-unable-to-calculate-average/300847/7 "2022-04-28T12:42:03Z")

</div>

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