Get a percent of the total grouped by a field in sumologic

286 views Asked by At

I have the following query

_sourceCategory=MyAppSource "data_event" 
| json "fish" , "count", "method"
| count > 5 and method == "good"?1:0 as approved

This gives me something like

Fish      count      method   approved
catfish   7          bad      0 
pike      8          good     1
bass      2          good     0
catfish   6          good     1
pike      7          good     1
bass      2          bad      0

I'm trying to transform it to show the percentage of approved, grouped by fish And maybe also the total count of fish

So for example

Fish     approved   count
catfish  50%        2
pike     100%       2
bass     0%         2

I realize i can sum(approved) and group the sum. I also know I can use count to get the total

So I could add the following

| count as total, sum(approved) as totalapproved group fish

But that just gives me

fish    total      totalapproved
catfish 2          1
pike    2          2
bass    2          0 

Not sure how to pull the ratio of the two and maintain the group by fish aspect.

Thanks for your help

1

There are 1 answers

1
ceiling cat On

It turned out to be a lot simpler than I thought. I can add another expression at the end to give me what I needed

| (totalapproved/total)*100 as percent

This gave me the percentage and continued to be broken down by fish.