Splunk Search

How do I use count multiple times in one search?

tcollins93
New Member

How do I use count multiple times in one search?

For example:

search * | stats count by f1, f2 count by f3, f4
Tags (2)
0 Karma

somesoni2
Revered Legend

Without much info, I would suggest this

search * | stats count by f1, f2 f3, f4
| appendpipe [| stats sum(count) as count by f1,f2 | eval keep=1]
| appendpipe [| stats sum(count) as count by f3,f4 | eval keep=1]
| where keep=1

gjanders
SplunkTrust
SplunkTrust

Your question is not very clear, but perhaps you are looking for eventstats?
That would allow you to run multiple stats commands over the data in different ways.

Or perhaps you want to combine your count with an eval statement? Examples are in previous posts or the documentation
The above will allow conditional counting

0 Karma

adonio
Ultra Champion

can you elaborate? maybe add some sample data and use case? if you have an idea of how you would like your results to look like it can also be very beneficial...
to your question, you can count by as many fields you want ... | stats count by f1 f2 f3 .... fN
hope it helps

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

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