# SQL expression to calculate the percentage

**URL:** https://discuss.elastic.co/t/sql-expression-to-calculate-the-percentage/271732
**Category:** Kibana
**Created:** [April 30, 2021, 2:15am UTC](https://discuss.elastic.co/t/sql-expression-to-calculate-the-percentage/271732 "2021-04-30T02:15:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![saintjohn](https://avatars.discourse-cdn.com/v4/letter/s/439d5e/32.png) [@saintjohn](https://discuss.elastic.co/u/saintjohn)
#### Post date: [April 30, 2021, 2:15am UTC](https://discuss.elastic.co/t/sql-expression-to-calculate-the-percentage/271732/1 "2021-04-30T02:15:23Z")

</div>

Hi experts,

I have a dataset like below, separated with data range.  
Field name is set to "test" where number of "≧-∞ and \< 1" is 1, and "≧1 and \<+∞" is 15.  
What I'm trying to do is to add a metric element in the center which shows percentage of "≧1 and \<+∞" which is 93.75%.  
What is the best SQL expression on a metric element to calculate the percantage?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/9/59f0b15f780628f45485967a67bbcdb138ba0fbe.png)

---

<div class="post-metadata">

### Author: ![jsanz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsanz/32/53734_2.png) [@jsanz](https://discuss.elastic.co/u/jsanz)
#### Post date: [May 4, 2021, 2:36pm UTC](https://discuss.elastic.co/t/sql-expression-to-calculate-the-percentage/271732/2 "2021-05-04T14:36:36Z")

</div>

Maybe this answer I posted in another thread on using [TSVB](https://www.elastic.co/guide/en/kibana/current/tsvb.html) with the `Metric Output` and the `Filter Ratio` metric may be helpful to you

> [@Show colored heading in the Kibana Dashboard](https://discuss.elastic.co/t/show-colored-heading-in-the-kibana-dashboard/272039/3):
>
> In fact, depending on your data query you may be able to do this using the Metric output in TSVB that has what is called Color Rules where you can change the background and text color based in the metric value. In my example I want a ratio between status: OK and status: Error so after switching to the Metric output, in Panel Options I can add the color rules to use 0.5 as my threshold And in the data use the Filter Ratio metric type for status: OK And in the options format…

---

<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: [June 1, 2021, 2:36pm UTC](https://discuss.elastic.co/t/sql-expression-to-calculate-the-percentage/271732/3 "2021-06-01T14:36:55Z")

</div>

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