Splunk Search

How to assign subsearches to multiple fields and evaluate their additions/subtractions

tunchi
New Member

I have a base search and there are multiple events that I can find depending on some set of the subtstring. Let's say A, B, C

I just want to get the counts of these events and calculate a single result from them.

This is what I got so far:

basesearch  |  stats count(eval(searchmatch("A should contain"))) as successA,
stats count(eval(searchmatch("B should contain"))) as failureB,
stats count(eval(searchmatch("C should contain"))) as failureC,
| eval overall = successA - failureB - failureC
| stats count by overall

...needless to say, it does not work.
Any simple ideas out there?

It's a very simple and basic question but I cannot find any entry or valid answer.
I appreciate any help.

Thanks,
Tunch

0 Karma

aberkow
Builder

Your main issue is that you only need to make one stats call, regardless of the number of functions you apply to it. Example:

basesearch
| stats count(x) as y, values(y) as z, avg(num) as avgNum

is valid Splunk, whereas yours is not. Another way you could've noticed this is by turning on syntax highlighting under your settings (click your name in the top right corner of the Splunk UI -> Preferences -> SPL Editor, Turn on Advanced Editor). I also like dark mode as my theme.

Let me know if I'm answering the wrong question, unclear what is pseudo code and real code in your search. Happy to take another shot if this doesn't work!

0 Karma
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...