# How to get percentage of failed tests from all results

**URL:** <https://discuss.elastic.co/t/how-to-get-percentage-of-failed-tests-from-all-results/282818>\
**Category:** Kibana\
**Created:** [August 30, 2021, 1:20pm UTC](https://discuss.elastic.co/t/how-to-get-percentage-of-failed-tests-from-all-results/282818 "2021-08-30T13:20:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShayWeizman](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@ShayWeizman](https://discuss.elastic.co/u/ShayWeizman)\
**Post date:** [August 30, 2021, 1:20pm UTC](https://discuss.elastic.co/t/how-to-get-percentage-of-failed-tests-from-all-results/282818/1 "2021-08-30T13:20:33Z")

</div>

Hi All,  
I'm using v 7.11.1  
I have this data structure in elastic:  
{  
"\_index" : "stamshay",  
"\_type" : "\_doc",  
"\_id" : "ub0ll3sB2oqJ9931yhZw",  
"\_score" : 1.0,  
"\_source" : {  
"buildVersion" : "1.1.1.1",  
"testcase" : {  
"$" : {  
"name" : "Forward To Isolation",  
"time" : "14.984",  
"className" : "Contains a log with events 'Network Request' and 'Forward To Isolation"  
}  
},  
"testcaseName" : "Forward To Isolation",  
"testcaseStatus" : "Passed",  
"timestamp" : "2021-08-30T13:00:41.053Z"  
}  
}

The record is a test result (One of many tests), the tests running few times a day (every 4h) I've create visualize "data table" that displayed the test name and the failed counts (And added filter for testcaseStatus.keyword : "Failed" ), it looks like:

Test Name count of records:  
"Forward To Isolation" 10

I want to add a column of test failed rate, I want to show how much times it failed from all runs, e.g. 10/200. (Means it failed 10 of 200 runs)

How it can be done?

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [August 31, 2021, 11:10pm UTC](https://discuss.elastic.co/t/how-to-get-percentage-of-failed-tests-from-all-results/282818/2 "2021-08-31T23:10:42Z")

</div>

You won't be able to do this with the aggregation-based data table, but you can do it using Lens. (See [Lens formulas](https://www.elastic.co/guide/en/kibana/current/lens.html#lens-formulas).)

Here's the instructions:

1. Create a new Lens visualization
2. Drag the `testcaseName` field to the center
3. Change the visualization type from "Bar vertical stacked" to "Table"
4. In the right column, under "Metrics", click on "Count of records"
5. Select the "Formula" tab
6. Enter the following for the formula: `count(kql='testcaseStatus.keyword:Failed') / count()`
7. Change the "Display name" to something like "Percent failed"
8. Under "Value format", select "Percent"

You should end up with something that looks like this:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/c/0c38b93563e1d043fac3cb1826cffb4452bbf620.jpeg)

Hope that helps! If you have any questions, let me know.

---

<div class="post-metadata">

**Author:** ![ShayWeizman](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@ShayWeizman](https://discuss.elastic.co/u/ShayWeizman)\
**Post date:** [September 1, 2021, 8:32am UTC](https://discuss.elastic.co/t/how-to-get-percentage-of-failed-tests-from-all-results/282818/3 "2021-09-01T08:32:28Z")

</div>

Hi Lukas,

Thank you for the response, in step 5, you mention select "Formula" tab, I don't have such tab??

See attached picture:

 ![Screenshot_1](https://us1.discourse-cdn.com/elastic/original/3X/d/e/de4810994cf846f711c2188453248c8a50d7314b.png)

Is this require some license?

Please advise.

Thanks.  
Shay

---

<div class="post-metadata">

**Author:** ![ghudgins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ghudgins/32/138532_2.png) [@ghudgins](https://discuss.elastic.co/u/ghudgins)\
**Post date:** [September 1, 2021, 1:04pm UTC](https://discuss.elastic.co/t/how-to-get-percentage-of-failed-tests-from-all-results/282818/4 "2021-09-01T13:04:19Z")

</div>

It was added in 7.14. You could also try the "Filter ratio" aggregation in TSVB for similar functionality in earlier versions!

---

<div class="post-metadata">

**Author:** ![ShayWeizman](https://avatars.discourse-cdn.com/v4/letter/s/7feea3/32.png) [@ShayWeizman](https://discuss.elastic.co/u/ShayWeizman)\
**Post date:** [September 1, 2021, 1:08pm UTC](https://discuss.elastic.co/t/how-to-get-percentage-of-failed-tests-from-all-results/282818/5 "2021-09-01T13:08:34Z")

</div>

Hi Graham,

If I want this feature I need to upgrade the Elastic? or Kibana?

Thanks

---

<div class="post-metadata">

**Author:** ![ghudgins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ghudgins/32/138532_2.png) [@ghudgins](https://discuss.elastic.co/u/ghudgins)\
**Post date:** [September 7, 2021, 6:59pm UTC](https://discuss.elastic.co/t/how-to-get-percentage-of-failed-tests-from-all-results/282818/6 "2021-09-07T18:59:21Z")

</div>

it's recommended you keep versions aligned between kibana & elasticsearch.

---

<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:** [October 5, 2021, 6:59pm UTC](https://discuss.elastic.co/t/how-to-get-percentage-of-failed-tests-from-all-results/282818/7 "2021-10-05T18:59:38Z")

</div>

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