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!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...