# Canvas calculate % change day on day on the same metric

**URL:** <https://discuss.elastic.co/t/canvas-calculate-change-day-on-day-on-the-same-metric/194431>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [August 8, 2019, 12:38pm UTC](https://discuss.elastic.co/t/canvas-calculate-change-day-on-day-on-the-same-metric/194431 "2019-08-08T12:38:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samgs](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@samgs](https://discuss.elastic.co/u/samgs)\
**Post date:** [August 8, 2019, 12:38pm UTC](https://discuss.elastic.co/t/canvas-calculate-change-day-on-day-on-the-same-metric/194431/1 "2019-08-08T12:38:54Z")

</div>

Hello,

Im trying to workout if its possible to show % movement day on day, on canvas?

For example, I have a sum of the number of page visits today and I want to compare if thats higher or lower than yesterday.

Is this possible on canvas?

---

<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:** [August 8, 2019, 2:15pm UTC](https://discuss.elastic.co/t/canvas-calculate-change-day-on-day-on-the-same-metric/194431/2 "2019-08-08T14:15:14Z")

</div>

Hi @samgs,

that's an interesting question.

It should by possible by doing something like this:

```auto
filters
| essql 
  query="SELECT DAY_OF_MONTH(timestamp) as day, COUNT(*) as count FROM \"kibana_sample_data_logs\" WHERE timestamp <= CURRENT_DATE() AND timestamp > CURRENT_DATE() - INTERVAL '2' DAY GROUP BY DAY_OF_MONTH(timestamp)"
| math "(last(count) - first(count)) / first(count)"
| render

```

The SQL query here returns a table like this:

```auto
day | count
 6 | 400
 7 | 200

```

The math function takes the first count and calculates the difference in percent to the second count which is current day and previous day.

If you want to be even more flexible (but with more complicated syntax), you can also use a Vega visualization - this [blog article](https://www.elastic.co/blog/custom-vega-visualizations-in-kibana) also explains how to build a trend indicator.

---

<div class="post-metadata">

**Author:** ![samgs](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@samgs](https://discuss.elastic.co/u/samgs)\
**Post date:** [August 9, 2019, 2:02pm UTC](https://discuss.elastic.co/t/canvas-calculate-change-day-on-day-on-the-same-metric/194431/3 "2019-08-09T14:02:35Z")

</div>

Thanks for the code @flash1293, I'll give that a go.

Do you know how to use vega on canvas? Is that even possible?

---

<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:** [August 9, 2019, 3:21pm UTC](https://discuss.elastic.co/t/canvas-calculate-change-day-on-day-on-the-same-metric/194431/4 "2019-08-09T15:21:49Z")

</div>

You can't use vega on canvas currently, it's just a regular visualization on the dashboard in that 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:** [September 6, 2019, 3:21pm UTC](https://discuss.elastic.co/t/canvas-calculate-change-day-on-day-on-the-same-metric/194431/5 "2019-09-06T15:21:50Z")

</div>

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