Splunk Search

To count the filed with different time range

parthiban
Path Finder

Hi 

I have events that having multiple countries... I want to count the country field and with different time range. It is need to sort by highest country to lowest.

EX   Country         Last 24h     Last 30 days     Last 90 days

           US                       10                   50                            100

           Aus                       8                     35                              80

I need query kindly assist me.


Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| bin _time span=1d
| stats count(eval(_time>=relative_time(now(),"@d-1d"))) as 24hCount  count(eval(_time>=relative_time(now(),"@d-30d"))) as 30dCount count(eval(_time>=relative_time(now(),"@d-90d"))) as 90dCount by Country

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust
| bin _time span=1d
| stats count(eval(_time>=relative_time(now(),"@d-1d"))) as 24hCount  count(eval(_time>=relative_time(now(),"@d-30d"))) as 30dCount count(eval(_time>=relative_time(now(),"@d-90d"))) as 90dCount by Country

parthiban
Path Finder

Hi @ITWhisperer 
The query is working, but the result is not as expected. The timeframe is also not returning the correct results. I need the highest count for the past 30 days, with the country having the highest count appearing first, followed by other countries in descending order.

The below is the current result.
parthiban_0-1728403827452.png

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

So how would this look? You can only sort in an particular order of precedence i.e. 30days first then if they are equal, 90days, then if still equal 1 day, you know that right?

0 Karma

parthiban
Path Finder

Hi @ITWhisperer 

I made small changes in given query. It is working as expected.. Thanks for your support

0 Karma

PickleRick
SplunkTrust
SplunkTrust
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 ...