Splunk Search

How to chart months on the X-axis in chronological order, not alphabetical?

hkosuru
Explorer

Hi,

My database query returns the following columns
monthNum,month,year,value
01, Jan, 2014, 20
01, Jan, 2015, 30
02, Feb, 2014, 40
02, Feb, 2015, 34
...
When I plot the chart with this data

|sort -monthNum| chart max(value) by month,year

I get months in alphabetical order on the X-axis. "sort -monthNum" does not seem to do anything. I want to see Calendar order- Jan, Feb, Mar

I don't want to prepend numbers to months like 1-Jan,2-Feb,3-Mar...

Thanks!

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

How about this

your base db search... | eval month=monthNum."-".month | chart max(value) by month,year | rex field=month "(?<monthNum>\d+)-(?<month>.*)" |sort -monthNum | fields - monthNum

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

How about this

your base db search... | eval month=monthNum."-".month | chart max(value) by month,year | rex field=month "(?<monthNum>\d+)-(?<month>.*)" |sort -monthNum | fields - monthNum

hkosuru
Explorer

Thank you! I just had add "reverse" for ascending order: |sort -monthNum | reverse| fields - monthNum

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Alternatively, you simply | sort monthNum (without -). That'll sort in ascending order.

0 Karma

hkosuru
Explorer

Thanks, yuanliu!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...