Dashboards & Visualizations

How can I make the months appear in alphabetical order without interfering with my chart legend in a stacked bar chart?

rkassabov
Path Finder

I want to preserve the logic, columns, and legend of the chart produced by my query but with months in chronological order rather than alphabetical. The solutions I found on here for correcting the month order seem to change the values used for my legend.

How can I make the months appear in alphabetical order without interfering with my chart legend?

|`init("xxx")`
| where strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N")>now() AND strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N")<=relative_time(now(), "+6mon")
| eval month=strftime(strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N"),"%b")
| table info_subType info_date_reported month
| chart count(info_subType) over month by info_subType
0 Karma
1 Solution

DalJeanis
Legend

Try this - if it does nto work, then continue as below:

 |`init("xxx")`
 | where strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N")>now() 
    AND strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N")<=relative_time(now(), "+6mon")
 | eval month = relative_time(strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N"),"@mon")
 | fields month info_subType
 | fieldformat month=strftime(month,"%b")
 | chart count over month by info_subType

If the above does not work...

ISO date format is YYYY-MM-DD. This way it is unambiguous, and can be sorted and compared directly without conversion.

If you really need the month written out, and if fieldformat does not work for chart then put the numeric year and month on the front of the formatted date first, like this:

2) | eval month=strftime(strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N"),""%Y-%m %b")

View solution in original post

DalJeanis
Legend

Try this - if it does nto work, then continue as below:

 |`init("xxx")`
 | where strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N")>now() 
    AND strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N")<=relative_time(now(), "+6mon")
 | eval month = relative_time(strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N"),"@mon")
 | fields month info_subType
 | fieldformat month=strftime(month,"%b")
 | chart count over month by info_subType

If the above does not work...

ISO date format is YYYY-MM-DD. This way it is unambiguous, and can be sorted and compared directly without conversion.

If you really need the month written out, and if fieldformat does not work for chart then put the numeric year and month on the front of the formatted date first, like this:

2) | eval month=strftime(strptime(info_date_reported,"%Y-%m-%d %H:%M:%S.%6N"),""%Y-%m %b")

rkassabov
Path Finder

The first one worked perfectly, thanks!

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...