Splunk Search

Combine stats count results

myoung54
Explorer

Hello all,

I feel kind of dumb even asking this question, but I've been up and down these forums looking for an answer and I just can't seem to figure this out. I have a stats count query that it showing results, and I'm trying to combine two of the results.

alt text

So in the picture above you can see "frown" has a count value, but in my case "no" is the same thing as "frown" and "smile" is also the same thing as "yes" so I'm trying to combine those values so the results look like this:
Sentiment Count
Bad 497
Good 7
Meh 26

I know I'll probably have to do some eval statement to combine the two but I just can't seem to figure it out! Any help would be very appreciated!

Labels (1)
0 Karma
1 Solution

myoung54
Explorer

Of course... Right when I ask the question I figure out the answer. For anyone else who runs into this, I used the below link to find my solution:
https://answers.splunk.com/answers/751141/combine-add-rows-in-the-search-results-using-a-wid.html

The line I added to my query was:

| eval Total=case(like(lower(sentiment),"frown"),"Bad", like(lower(sentiment),"no"),"Bad", like(lower(sentiment),"smile"),"Good", like(lower(sentiment),"yes"),"Good", like(lower(sentiment),"meh"),"Meh"),1=1,Total)
| stats count by Total

View solution in original post

myoung54
Explorer

Of course... Right when I ask the question I figure out the answer. For anyone else who runs into this, I used the below link to find my solution:
https://answers.splunk.com/answers/751141/combine-add-rows-in-the-search-results-using-a-wid.html

The line I added to my query was:

| eval Total=case(like(lower(sentiment),"frown"),"Bad", like(lower(sentiment),"no"),"Bad", like(lower(sentiment),"smile"),"Good", like(lower(sentiment),"yes"),"Good", like(lower(sentiment),"meh"),"Meh"),1=1,Total)
| stats count by Total

jpolvino
Builder

You can further group like this, with line breaks for readability:

| eval Total=case(like(lower(sentiment),"frown") OR like(lower(sentiment),"no"),"Bad",
like(lower(sentiment),"smile") OR like(lower(sentiment),"yes"),"Good",
like(lower(sentiment),"meh"),"Meh",
1==1,Total)
| stats count by Total
0 Karma
Get Updates on the Splunk Community!

Enhance Security Visibility with Splunk Enterprise Security 7.1 through Threat ...

(view in My Videos)Struggling with alert fatigue, lack of context, and prioritization around security ...

Troubleshooting the OpenTelemetry Collector

  In this tech talk, you’ll learn how to troubleshoot the OpenTelemetry collector - from checking the ...

Adoption of Infrastructure Monitoring at Splunk

  Splunk's Growth Engineering team showcases one of their first Splunk product adoption-Splunk Infrastructure ...