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!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...