# Problem in getting percentage in canvas

**URL:** <https://discuss.elastic.co/t/problem-in-getting-percentage-in-canvas/296927>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [February 11, 2022, 3:54am UTC](https://discuss.elastic.co/t/problem-in-getting-percentage-in-canvas/296927 "2022-02-11T03:54:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dannie-ml](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dannie-ml/32/99559_2.png) [@dannie-ml](https://discuss.elastic.co/u/dannie-ml)\
**Post date:** [February 11, 2022, 3:54am UTC](https://discuss.elastic.co/t/problem-in-getting-percentage-in-canvas/296927/1 "2022-02-11T03:54:17Z")

</div>

Hi, im having a problem with this expression. What I have done is get the error percentage, i.e, I have for example 643 transactions with 49 errors what I want is the error percentage. The expression work well but when I have 0 transactions and 0 errors I get an evident error [math] cannot divide by 0, is there a solution to avoid this problem?  
This is what I have:

```auto
filters 
  |essql 
  query = {string "SELECT COUNT(document.name) as total1 FROM \"nowo_apicalls-dev*\" WHERE document.name = 'id-check' and document.statusCode BETWEEN 200 AND 299"}
| var_set name="field1" value={getCell "total1"}
| filters 
  | essql 
  query = {string "SELECT count(document.statusCode) as total2 FROM \"nowo_api_calls_int*\" where document.name = 'id-check' and document.statusCode != 200 "}
  | var_set name="field2" value={getCell "total2"}
| var_set name ="result" value={math {string {var field1} " - " {var field2}}}
| filters 
  | essql 
  query = {string "SELECT count(document.statusCode) as total3 FROM \"nowo_api_calls_int*\" where document.name = 'id-check' and document.statusCode != 200 "}
  | var_set name="field3" value={getCell "total3"}
  | math {string {var field3} " / " {var result} * 100}
| formatnumber "0%"

```

---

<div class="post-metadata">

**Author:** ![dannie-ml](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dannie-ml/32/99559_2.png) [@dannie-ml](https://discuss.elastic.co/u/dannie-ml)\
**Post date:** [February 11, 2022, 9:11pm UTC](https://discuss.elastic.co/t/problem-in-getting-percentage-in-canvas/296927/2 "2022-02-11T21:11:35Z")

</div>

I solved the problem with the cero with a condition. But now I want to avoid negative numbers, can anyone help me in how to use the property of absule value abs() in this case?

---

<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:** [March 11, 2022, 9:11pm UTC](https://discuss.elastic.co/t/problem-in-getting-percentage-in-canvas/296927/3 "2022-03-11T21:11:56Z")

</div>

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