# How to get total passed tests divided by total executed tests on a metric?

**URL:** <https://discuss.elastic.co/t/how-to-get-total-passed-tests-divided-by-total-executed-tests-on-a-metric/236225>\
**Category:** Kibana\
**Created:** [June 8, 2020, 8:13pm UTC](https://discuss.elastic.co/t/how-to-get-total-passed-tests-divided-by-total-executed-tests-on-a-metric/236225 "2020-06-08T20:13:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goishin](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Goishin](https://discuss.elastic.co/u/Goishin)\
**Post date:** [June 8, 2020, 8:13pm UTC](https://discuss.elastic.co/t/how-to-get-total-passed-tests-divided-by-total-executed-tests-on-a-metric/236225/1 "2020-06-08T20:13:59Z")

</div>

I'm struggling to figure out how to display a metric. I'm trying to display the overall pass rate of test passes. In my index, I have a scripted field which has total\_tests, it is a sum of the following three fields:

```auto
results.passed_tests
results.skipped_tests
results.failed_tests

```

I'd like to display a metric which is a sum of results.passed\_tests divided by the sum of total\_tests.

In other words, I'd like to display

```auto
(results.passed_tests)/(results.passed_tests+results.skipped_tests+results.failed_tests).

```

I can get the overall sum of tests executed. And I can get the overall sum of results.passed\_tests. And I can get both of those displayed on the metric widget at the same time. But the final part, the results-passed/total-tests part? I just can't figure it out. Can someone guide me, please?

---

<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:** [June 9, 2020, 12:18pm UTC](https://discuss.elastic.co/t/how-to-get-total-passed-tests-divided-by-total-executed-tests-on-a-metric/236225/2 "2020-06-09T12:18:53Z")

</div>

You can do this with TSVB by using the "Math" aggregation:

 ![Screenshot 2020-06-09 at 14.17.01](https://us1.discourse-cdn.com/elastic/original/3X/7/0/708c32d60de79487d3c1b57645ad3a72f3efd97e.png)

Make sure to set the "timerange mode" to "entire time range" in the panel options so to metric is calculated for all of the data in your current time range instead of just the last bucket:

 ![Screenshot 2020-06-09 at 14.17.08](https://us1.discourse-cdn.com/elastic/original/3X/4/c/4ca44bcc6a0e205af7267c0171712282af8b284c.png)

---

<div class="post-metadata">

**Author:** ![Goishin](https://avatars.discourse-cdn.com/v4/letter/g/46a35a/32.png) [@Goishin](https://discuss.elastic.co/u/Goishin)\
**Post date:** [June 9, 2020, 3:32pm UTC](https://discuss.elastic.co/t/how-to-get-total-passed-tests-divided-by-total-executed-tests-on-a-metric/236225/3 "2020-06-09T15:32:39Z")

</div>

Yup, that worked like a charm! That was great! And I had no idea how to use TSVB before this. Now, not only do I have my metric, but you taught me how to use this widget! Great stuff!

---

<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:** [July 7, 2020, 3:32pm UTC](https://discuss.elastic.co/t/how-to-get-total-passed-tests-divided-by-total-executed-tests-on-a-metric/236225/4 "2020-07-07T15:32:53Z")

</div>

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