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
Get Updates on the Splunk Community!

Index This | How many sides does a circle have?

  March 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this ...

New This Month - Splunk Observability updates and improvements for faster ...

What’s New? This month, we’re delivering several enhancements across Splunk Observability Cloud for faster and ...

What's New in Splunk Cloud Platform 9.3.2411?

Hey Splunky People! We are excited to share the latest updates in Splunk Cloud Platform 9.3.2411. This release ...