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!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...