# Kibana Canvas , Calculate percentage using to aggregations

**URL:** <https://discuss.elastic.co/t/kibana-canvas-calculate-percentage-using-to-aggregations/190702>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [July 16, 2019, 9:52am UTC](https://discuss.elastic.co/t/kibana-canvas-calculate-percentage-using-to-aggregations/190702 "2019-07-16T09:52:07Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Catherine\_Liu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/catherine_liu/32/34294_2.png) [@Catherine\_Liu](https://discuss.elastic.co/u/Catherine_Liu)\
**Post date:** [July 18, 2019, 10:21pm UTC](https://discuss.elastic.co/t/kibana-canvas-calculate-percentage-using-to-aggregations/190702/4 "2019-07-18T22:21:41Z")

</div>

This is a little complex, but I believe what you want is possible in Canvas. Essentially you need to query your index twice in the same expression to get the two different counts, and it also utilizes filter groups which was introduced in Kibana 7.2.0. I assume you wanted both counts to be filtered by the same time filter to filter your date field.

Here's the example using the ecommerce sample data set:

![Jul-18-2019%2015-16-52](https://us1.discourse-cdn.com/elastic/original/3X/0/c/0c1808d28aa0d1341ab3bb9c30c96194b11f14c0.gif)

Time filter on `order_date`:

```auto
timefilterControl compact=true column="order_date" filterGroup="order_date"
| render

```

Dropdown filter on `customer_gender`:

```auto
esdocs index="kibana_sample_data_ecommerce" fields="customer_gender"
| dropdownControl valueColumn="customer_gender" filterColumn="customer_gender" filterGroup="gender"
| render

```

Metric that displays the percentage of orders made by the gender you're filtering by

```auto
filters group="order_date" group="gender" ungrouped=true
| essql 
    query="SELECT order_date, customer_gender FROM \"kibana_sample_data_ecommerce\""
    count=10000
| math { 
    string "count(customer_gender)/" 
      {filters group="order_date" ungrouped=true 
       | essql query="SELECT order_date, customer_gender FROM \"kibana_sample_data_ecommerce\""
           count=10000
       | math "count(customer_gender)"
      } 
  }
| formatnumber "0%"
| metric
  metricFont={font size=48 family="'Open Sans', Helvetica, Arial, sans-serif" color="#000000" align="center" lHeight=48} 
  labelFont={font size=14 family="'Open Sans', Helvetica, Arial, sans-serif" color="#000000" align="center"}
| render

```

---

_[View the full topic](https://discuss.elastic.co/t/kibana-canvas-calculate-percentage-using-to-aggregations/190702)._
