Splunk Search

How do you display days in chronological order not alphabetically?

cwhurd1
New Member

Hi,

I am using the below search to display the average transactions by day over a couple weeks. I need the days to show in chronological order. I have seen the Splunk Documentation, and I am still not able to figure it out. Any advice will be beneficial:

index=XXX sourcetype=XXXXX
| timechart span=1h dc(transactionID) as transactions
| eval weekday=strftime(_time,"%A")
| eval hour=strftime(_time,"%H")
| chart avg(transactions) as transactions by hour, weekday
Tags (1)
0 Karma
1 Solution

somesoni2
Revered Legend

Give this a try

 index=XXX sourcetype=XXXXX
 | timechart span=1h dc(transactionID) as transactions
 | eval weekday=strftime(_time,"%A")
 | eval hour=strftime(_time,"%H")
 | chart avg(transactions) as transactions by hour, weekday
| table hour Sunday Monday Tuesday Wednesday Thursday Friday Saturday

View solution in original post

somesoni2
Revered Legend

Give this a try

 index=XXX sourcetype=XXXXX
 | timechart span=1h dc(transactionID) as transactions
 | eval weekday=strftime(_time,"%A")
 | eval hour=strftime(_time,"%H")
 | chart avg(transactions) as transactions by hour, weekday
| table hour Sunday Monday Tuesday Wednesday Thursday Friday Saturday

cwhurd1
New Member

This worked! Thank you!

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@cwhurd1

Can you please try below search?

index=XXX sourcetype=XXXXX
 | timechart span=1h dc(transactionID) as transactions
 | eval weekday=strftime(_time,"%w")."_".strftime(_time,"%A")
 | eval hour=strftime(_time,"%H")
 | chart avg(transactions) as transactions by hour, weekday
 | rename 1_* as *,2_* as *,3_* as *,4_* as *,5_* as *,6_* as *,0_* as *

My Sample Search:

index=*
 | timechart span=1h count as transactions
 | eval weekday=strftime(_time,"%w")."_".strftime(_time,"%A")
 | eval hour=strftime(_time,"%H")
 | chart avg(transactions) as transactions by hour, weekday | rename 1_* as *,2_* as *,3_* as *,4_* as *,5_* as *,6_* as *,0_* as *

Here we know Splunk displays column name in alphabetical order, so I have provided day number as initial character of weekday and then renamed it.

thanks

0 Karma

cwhurd1
New Member

This did not work for me. It returned the same results.

0 Karma

niketn
Legend

@kamlesh_vaghela this will fail if Selected Time spans across multiple weeks as stated in the question 😉

%w (Week day from 0-6) and %A (Week day from Sunday- Saturday) will match for same days of the week so they will appear next to each other.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Splunk Mobile: Your Brand-New Home Screen

Meet Your New Mobile Hub  Hello Splunk Community!  Staying connected to your data—no matter where you are—is ...

Introducing Value Insights (Beta): Understand the Business Impact your organization ...

Real progress on your strategic priorities starts with knowing the business outcomes your teams are delivering ...

Enterprise Security (ES) Essentials 8.3 is Now GA — Smarter Detections, Faster ...

As of today, Enterprise Security (ES) Essentials 8.3 is now generally available, helping SOC teams simplify ...