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

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 ??

Hey @Jim_Boutcher,

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

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