Dashboards & Visualizations

how to count the field with conditions

Dattasri
Loves-to-Learn

Dattasri_0-1712213665473.png

 

Labels (2)
0 Karma

KothariSurbhi
Loves-to-Learn Everything

Hello @Dattasri ,

You can use the below mentioned search query in which I have used the random function to generate values between 0 and 100, and then applied the `stats count` command.

| makeresults count=10
| eval rand=(random() % 100) + 1
| stats count(eval(rand > 60)) as count_greater_than_60, count(eval(rand < 60)) as count_less_than_60


If this reply helps you, Karma would be appreciated.

Thanks,
Surbhi

 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

You can use appendpipe command for this - https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Appendpipe

Either creating a temporary fields and counting them (which is a more straightforward solution)

| eval is_small=if(your_field<threshold,1,0)
| eval is_big=if(your_field>another_threshold,1,0)
| appendpipe sum(is_small) as "Small Values" sum(is_big) as "Big Values"

Alternatively to creating temporary fields you can use the eval-based stats like

sum(eval(if(your_field>another_threshold,1,0))) as "Big Values"

But this is more advanced functionality and this syntax can be a bit confusing.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...

Observe and Secure All Apps with Splunk

 Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

What's New in Splunk Observability - August 2025

What's New We are excited to announce the latest enhancements to Splunk Observability Cloud as well as what is ...