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 Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...