Splunk Search

How to combine stats count results?

raindrop18
Communicator

I have this string and I want the output for this result to be combined on one line and also sum the results

index="grade-stat" host ="student" source="exam"| 
eval Result=case(match(_raw,"Pass"),"Result Successful", 
match(_raw,"Fail"),"Result failed" ) |  stats count by  Grade, Result

**current output
Grade-A Result Successful 125675
Grade-A Result failed 4004
Grade-B Result Successful 145134
Grade-B Result failed 2695

***desired result

Grade-A Result Successful 125675 Result failed 4004 total= 129679
Grade-B Result Successful 145134 Result failed 2695 total= 147824

What I need is the output to be on same line instead 2 lines for each grade, and if possible, to sum the success and failed count.

thanks,

0 Karma
1 Solution

justinatpnnl
Communicator

Would something like this work for you?

index="grade-stat" host="student" source="exam"
| stats count(eval(_raw LIKE "%Pass%")) as "Result Successful" , count(eval(_raw LIKE "%Fail%")) as "Result failed" by Grade
| addtotals

That would give you something like this:

Grade   Result Success  Result Failed   Total
A       125675          4004             129679
B       145134          2695             147829

View solution in original post

justinatpnnl
Communicator

Would something like this work for you?

index="grade-stat" host="student" source="exam"
| stats count(eval(_raw LIKE "%Pass%")) as "Result Successful" , count(eval(_raw LIKE "%Fail%")) as "Result failed" by Grade
| addtotals

That would give you something like this:

Grade   Result Success  Result Failed   Total
A       125675          4004             129679
B       145134          2695             147829

raindrop18
Communicator

working perfectly, thanks you so very much.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...