Kibana: Unable to calculate average

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.

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?

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

So your documents look like this?

{  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

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.

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

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

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

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