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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...