Splunk Search

How to use where to compare field values

summitsplunk
Communicator

Let's say I'm doing a stats count by x,y

How would I formulate a WHERE that compares the string value of x and y and only returns the stats count when there's a difference.

So like stats count by x,y |where x != y

0 Karma

richgalloway
SplunkTrust
SplunkTrust

Put the where clause before the stats to reduce the number of events to process.

... | where 'x' != 'y' | stats count by x,y

The single quotes tell Splunk to treat x and y as field names rather than strings.

---
If this reply helps you, Karma would be appreciated.
0 Karma

Vijeta
Influencer

@summitsplunk Is your query not working. What are the values in x and y can you give an example.

0 Karma
Get Updates on the Splunk Community!

Fueling your curiosity with new Splunk ILT and eLearning courses

At Splunk Education, we’re driven by curiosity—both ours and yours! That’s why we’re committed to delivering ...

Splunk AI Assistant for SPL 1.1.0 | Now Personalized to Your Environment for Greater ...

Splunk AI Assistant for SPL has transformed how users interact with Splunk, making it easier than ever to ...

Unleash Unified Security and Observability with Splunk Cloud Platform

     Now Available on Microsoft AzureOn Demand Now Step boldly into the AI revolution with enhanced security ...