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’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

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

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...