Splunk Search

Why isn't my search sorting events chronologically by month?

Yaichael
Communicator

I'm executing the following search to generate a report with columns sorted chronologically by month:

( ... ) | eval month_num = strftime( _time ,"%m" ) | stats count by date_month | sort - month_num

date_month = month field taken from the events' data

Splunk can't still interpret the chronological order of the months.

What am I missing?

Thanks for the help!

0 Karma
1 Solution

somesoni2
Revered Legend

There is no month_num field after stats, hence the sort fails. Try this

( ... ) | eval month_num = strftime( _time ,"%m" ) | stats count by date_month month_num | sort - month_num | fields - month_num

View solution in original post

0 Karma

somesoni2
Revered Legend

There is no month_num field after stats, hence the sort fails. Try this

( ... ) | eval month_num = strftime( _time ,"%m" ) | stats count by date_month month_num | sort - month_num | fields - month_num
0 Karma

Yaichael
Communicator

I added the reverse command to your query and it worked exactly as I wanted it.

Thanks!

0 Karma

somesoni2
Revered Legend

You could also, just remove hyphen from the sort command (which sorts in descending order) to use just sort month_num.

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

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