# Canvas - Render a metric generated based in other two metrics

**URL:** <https://discuss.elastic.co/t/canvas-render-a-metric-generated-based-in-other-two-metrics/276558>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [June 21, 2021, 3:20pm UTC](https://discuss.elastic.co/t/canvas-render-a-metric-generated-based-in-other-two-metrics/276558 "2021-06-21T15:20:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![clino](https://avatars.discourse-cdn.com/v4/letter/c/5fc32e/32.png) [@clino](https://discuss.elastic.co/u/clino)\
**Post date:** [June 21, 2021, 3:20pm UTC](https://discuss.elastic.co/t/canvas-render-a-metric-generated-based-in-other-two-metrics/276558/1 "2021-06-21T15:20:44Z")

</div>

I am looking to have configure a metric in Canvas to cover the following scenario: Calculate the total amount of sales all time divided by total sales in specific timeframe (i.e. first 3 months). I see within TSVB I can create one metric for all time and one other for specific timeframe. However, I am unable to put both together to calculate required metric. Is there any way I can do that to render into Canvas, using Kibana Visualizations or Timelion?

---

<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 22, 2021, 11:27am UTC](https://discuss.elastic.co/t/canvas-render-a-metric-generated-based-in-other-two-metrics/276558/2 "2021-06-22T11:27:13Z")

</div>

In canvas you can do something like this:

```auto
filters
| essql query="SELECT sum(bytes) as bytes FROM \"kibana_sample_data_logs\""
| math {string {filters | essql query="SELECT sum(bytes) as bytes FROM \"kibana_sample_data_logs\" WHERE timestamp > (CURRENT_DATE - INTERVAL 1 DAY)" | getCell} " / bytes"}
| metric "Ratio"

```

It's fetching one data point using `essql`, then executing the math function on the result with the math expression being constructed using the result of a second `essql` call containing the other data point.

---

<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 20, 2021, 11:28am UTC](https://discuss.elastic.co/t/canvas-render-a-metric-generated-based-in-other-two-metrics/276558/3 "2021-07-20T11:28:13Z")

</div>

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