Splunk Search

Is there an alternate solution to stats count with two BY fields?

jialiu907
Path Finder

 

| eval ExitStatus=if(ExitStatus>0, 1, 0)
| stats count by ExitStatus by Site

 

In the search query above, I am looking to count the ExitStatus field after evaluating it to 2 stats, 0 or 1; by the Site, which is 4 stats.  Currently the search query isn't showing any statistics and I think its due to the two BY commands. Is there an alternative solution?

Labels (3)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @jialiu907,

please try this:

<your_search>
| stats 
   count(eval(ExitStatus>0)) AS greater_than 
   count(eval(ExitStatus=0)) AS less_than 
   BY Site

Ciao.

Giuseppe

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

If you want to categorize your data with stats over more than one field, you simply enumerate those fields with a single BY clause.

[...]
| stats count BY ExitStatus Site

 Of course pay attention to field names - they are case-sensitive.

gcusello
SplunkTrust
SplunkTrust

Hi @jialiu907,

please try this:

<your_search>
| stats 
   count(eval(ExitStatus>0)) AS greater_than 
   count(eval(ExitStatus=0)) AS less_than 
   BY Site

Ciao.

Giuseppe

Get Updates on the Splunk Community!

Splunk Observability Cloud | Customer Survey!

If you use Splunk Observability Cloud, we invite you to share your valuable insights with us through a brief ...

.conf23 | Get Your Cybersecurity Defense Analyst Certification in Vegas

We’re excited to announce a new Splunk certification exam being released at .conf23! If you’re going to Las ...

Starting With Observability: OpenTelemetry Best Practices

Tech Talk Starting With Observability: OpenTelemetry Best Practices Tuesday, October 17, 2023   |  11AM PST / ...