# Using ? to display a ratio of two queries or other advanced calculations

**URL:** <https://discuss.elastic.co/t/using-to-display-a-ratio-of-two-queries-or-other-advanced-calculations/135163>\
**Category:** Elasticsearch\
**Created:** [June 8, 2018, 1:35pm UTC](https://discuss.elastic.co/t/using-to-display-a-ratio-of-two-queries-or-other-advanced-calculations/135163 "2018-06-08T13:35:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![topel](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@topel](https://discuss.elastic.co/u/topel)\
**Post date:** [June 8, 2018, 1:35pm UTC](https://discuss.elastic.co/t/using-to-display-a-ratio-of-two-queries-or-other-advanced-calculations/135163/1 "2018-06-08T13:35:42Z")

</div>

I have been struggling to find a visualization solution that fits my company's needs. I do not only need to visualize time series data but also need to be able to do calculations "vertically" across all the data at one point of time (averages/ratios) as well as "horizontally" across different points of time if possible (see my question [here](https://discuss.elastic.co/t/calculate-mtbf-mttf-mean-time-between-to-failure-for-a-visualization/134995) trying to achieve this with kibana).

Displaying averages in Grafana for example is no problem, but I already struggle when it comes to calculating a ratio of the kind (successful runs/all runs) because when using the lucene syntax to query elasticsearch there is no option to use calculations..

I am open to any visualization solution that could accomplish this, grafana, kibana, banana, I dont care as long as it works.. Thanks for the help.

Edit: To give a usecase without you having to click the link: I need to calculate the mean time between failures for jenkins pipelines. So the time between one build with result: "FAILURE" to the next one with a different ID with the result == "FAILURE".

Cheers,  
Tobias

---

<div class="post-metadata">

**Author:** ![topel](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@topel](https://discuss.elastic.co/u/topel)\
**Post date:** [June 14, 2018, 8:11am UTC](https://discuss.elastic.co/t/using-to-display-a-ratio-of-two-queries-or-other-advanced-calculations/135163/2 "2018-06-14T08:11:07Z")

</div>

bump

---

<div class="post-metadata">

**Author:** ![jhg](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@jhg](https://discuss.elastic.co/u/jhg)\
**Post date:** [June 14, 2018, 9:30am UTC](https://discuss.elastic.co/t/using-to-display-a-ratio-of-two-queries-or-other-advanced-calculations/135163/3 "2018-06-14T09:30:29Z")

</div>

Using an Area visualization you could follow the following steps in order to get a ratio overview of any information that is available:

- In Area visualization, choose X-axis \> data aggregation \> Date histogram (just for this example, you can choose other dimensions also)
- Split series \> Sub aggregation \> filters for instance a filter "jenkins\_result:ok" and "NOT jenkins\_result:ok". You see both filters being complement to each other.
- Goto Metric&Axes, Y-axis \> LeftAxis-1 \> Mode \> percentage

Using this approach you could choose other Splits or dimensions.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![topel](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@topel](https://discuss.elastic.co/u/topel)\
**Post date:** [June 14, 2018, 12:51pm UTC](https://discuss.elastic.co/t/using-to-display-a-ratio-of-two-queries-or-other-advanced-calculations/135163/4 "2018-06-14T12:51:48Z")

</div>

Hello @jhg and welcome to this forums I suppose,

Your solution does work for sure, when using kibana there is also the option I found to use timelion to display some basic calculations and thus get a visual of a ratio but I can not get the mean-time between failure part to work in kibana without adding additional metrics to my data.

Even worse is the experience in Grafana, where I can not even get the ratio displayed, not even speaking of the MTBF.

Still thanks a lot for jumping right to my help soon after signing up on the forums,

Best,  
Tobias

---

<div class="post-metadata">

**Author:** ![jhg](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@jhg](https://discuss.elastic.co/u/jhg)\
**Post date:** [June 14, 2018, 2:18pm UTC](https://discuss.elastic.co/t/using-to-display-a-ratio-of-two-queries-or-other-advanced-calculations/135163/5 "2018-06-14T14:18:12Z")

</div>

Hi Tobias,  
Ah, I misread the part about the MTBF. Interesting question.  
Visualizations are not the issue. For a MTBF I guess some iteration is necessary or preprocessing the data with for instance logstash.

Too bad the answer is not here yet

Regards,  
Jaap

---

<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 12, 2018, 2:18pm UTC](https://discuss.elastic.co/t/using-to-display-a-ratio-of-two-queries-or-other-advanced-calculations/135163/6 "2018-07-12T14:18:17Z")

</div>

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