# Canvas - percentage of docs having specific value in a field (row by row)

**URL:** <https://discuss.elastic.co/t/canvas-percentage-of-docs-having-specific-value-in-a-field-row-by-row/205559>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [October 28, 2019, 10:36pm UTC](https://discuss.elastic.co/t/canvas-percentage-of-docs-having-specific-value-in-a-field-row-by-row/205559 "2019-10-28T22:36:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Boutcher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jim_boutcher/32/56725_2.png) [@Jim\_Boutcher](https://discuss.elastic.co/u/Jim_Boutcher)\
**Post date:** [October 28, 2019, 10:36pm UTC](https://discuss.elastic.co/t/canvas-percentage-of-docs-having-specific-value-in-a-field-row-by-row/205559/1 "2019-10-28T22:36:51Z")

</div>

Given these docs (let's say they represent vehicles sold)

```
docA : { "make": "Ford", "model": "Mustang", "vehicleType": "SportsCar" } 
docA : { "make": "Ford", "model": "Mustang", "vehicleType": "SportsCar" } 
docA : { "make": "Ford", "model": "Taurus", "vehicleType": "Sedan" } 
docA : { "make": "Chevrolet", "model": "Astro", "vehicleType": "Minivan" } 
docA : { "make": "Chevrolet", "model": "Corvette", "vehicleType": "SportsCar" } 
docA : { "make": "Chevrolet", "model": "Malibu", "vehicleType": "Sedan" } 

```

I'd like to be able to display a dataset that looks like this:

```
**Make % Sports Cars % Minivans**
Ford 66% 0%
Chevrolet 33% 33%

```

Where I've gotten to, but I'm getting some odd errors, and I'm questioning my approach:

```
filters 
| esdocs index="carsales" fields="make,vehicleType"
| ply by="make" fn={rowCount | as "row_count"}
| staticColumn column="allSalesByMake" value={ filters | escount { string "make:" make } index="carsales" }
// and then I planned on adding another static column, whose value was row_count / allSalesByMake

```

Is this the right approach? If so, I'm unable it seems to build a dynamic ES query and pass to escount ??

---

<div class="post-metadata">

**Author:** ![tims](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tims/32/46750_2.png) [@tims](https://discuss.elastic.co/u/tims)\
**Post date:** [November 18, 2019, 3:31pm UTC](https://discuss.elastic.co/t/canvas-percentage-of-docs-having-specific-value-in-a-field-row-by-row/205559/2 "2019-11-18T15:31:36Z")

</div>

Hey @Jim_Boutcher,

Here's an example of calculating percentages in Canvas, let me know if this helps.

> [@Kibana Canvas , Calculate percentage using to aggregations](https://discuss.elastic.co/t/kibana-canvas-calculate-percentage-using-to-aggregations/190702/4):
>
> 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…

---

<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:** [December 16, 2019, 3:31pm UTC](https://discuss.elastic.co/t/canvas-percentage-of-docs-having-specific-value-in-a-field-row-by-row/205559/3 "2019-12-16T15:31:38Z")

</div>

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