How to get percentage of failed tests from all results

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" : "",
"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?

You won't be able to do this with the aggregation-based data table, but you can do it using Lens. (See 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:

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

1 Like

Hi Lukas,

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

See attached picture:

Is this require some license?

Please advise.


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

Hi Graham,

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


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

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