Splunk Search

Simple eval + stats count by 2 fields not working

the_wolverine
Champion

What am I doing wrong? I've tried several iterations of the following all which return 2 columns with a count of 0:

sourcetype=a  OR sourcetype=b | stats count   
   count(eval(sourcetype=a)) AS a_count   
   count(eval(sourcetype=b)) AS b_count
  • "sourcetype=a OR sourcetype=b | stats count by sourcetype" <= returns the correct counts but I'm unable to split the count out for further evaluation. I need to be able to eval diff=(b_count-a_count).
Tags (1)
1 Solution

the_wolverine
Champion

OMG. I got it to work by changing '=' to '==' and putting the value in quotes! HOW FICKLE!!

sourcetype=a  OR sourcetype=b | stats count  as Total
   count(eval(sourcetype=="a")) AS a_count   
   count(eval(sourcetype=="b")) AS b_count

View solution in original post

AFAS
Explorer

I was looking for this for days! Thanks the_wolverine

0 Karma

shikhanshu
Path Finder

Exact same situation and exact same reaction. OMG. 🙂

the_wolverine
Champion

OMG. I got it to work by changing '=' to '==' and putting the value in quotes! HOW FICKLE!!

sourcetype=a  OR sourcetype=b | stats count  as Total
   count(eval(sourcetype=="a")) AS a_count   
   count(eval(sourcetype=="b")) AS b_count

cmak
Contributor

So glad I found this 🙂

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...