Kibana Canvas , Calculate percentage using to aggregations

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

Time filter on order_date:

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

Dropdown filter on customer_gender:

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

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
1 Like