<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: In the following searches, how come the days of the week are not sorting correctly? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421137#M174237</link>
    <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/145622"&gt;@net1993&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;Regarding your first search: You are losing the sort_field field after running the chart command.&lt;BR /&gt;
In the second search, the chart command does not care about the ordering of events.&lt;/P&gt;

&lt;P&gt;Try replacing the last two lines of your first search with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | stats count by date_wday,sort_field
 | sort sort_field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will keep the sort_field available.&lt;/P&gt;

&lt;P&gt;Alternatively, run the chart/stats command first and afterwards the eval+sort commands:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| ...
| stats count by date_wday
| eval sort_field=case(date_wday=="monday",1, date_wday=="tuesday",2, date_wday=="wednesday",3, date_wday=="thursday",4, date_wday=="friday",5, date_wday=="weekend",6)
| sort sort_field | fields - sort_field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;On a side note: Are you sure that events such as date_wday="weekend" exist? Because I am seeing date_wday="sunday" in my Splunk.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 22:21:10 GMT</pubDate>
    <dc:creator>whrg</dc:creator>
    <dc:date>2020-09-29T22:21:10Z</dc:date>
    <item>
      <title>In the following searches, how come the days of the week are not sorting correctly?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421136#M174236</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;This is driving me crazy.&lt;/P&gt;

&lt;P&gt;Splunk is sorting results from friday — monday... instead of monday, tuesday, etc...&lt;/P&gt;

&lt;P&gt;Search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(earliest="11/25/2018:00:00:00" index="_audit" sourcetype="audittrail" (action="rtsearch" OR action="search" OR action="accelerate_search" ) action=*  )
OR (earliest="11/25/2018:00:00:00" index="_internal"  sourcetype="scheduler" search_type="scheduled" (status="skipped" OR status="success") )
|fields index, date_wday, status
| eval wd=lower(date_wday) 
| eval sort_field=case(wd=="monday",1, wd=="tuesday",2, wd=="wednesday",3, wd=="thursday",4, wd=="friday",5, wd=="weekend",6)
|chart limit=0 useother=f usenull=f count  over date_wday
|sort sort_field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(earliest="11/25/2018:00:00:00" index="_audit" sourcetype="audittrail" (action="rtsearch" OR action="search" OR action="accelerate_search" ) action=*  )
OR (earliest="11/25/2018:00:00:00" index="_internal"  sourcetype="scheduler" search_type="scheduled" (status="skipped" OR status="success") )
|fields index, date_wday, status
| eval wd=lower(date_wday) 
| eval sort_field=case(wd=="monday",1, wd=="tuesday",2, wd=="wednesday",3, wd=="thursday",4, wd=="friday",5, wd=="weekend",6)
|sort 0 sort_field
|chart limit=0 useother=f usenull=f count  over date_wday
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 14:53:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421136#M174236</guid>
      <dc:creator>net1993</dc:creator>
      <dc:date>2018-12-05T14:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: In the following searches, how come the days of the week are not sorting correctly?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421137#M174237</link>
      <description>&lt;P&gt;Hello &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/145622"&gt;@net1993&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;Regarding your first search: You are losing the sort_field field after running the chart command.&lt;BR /&gt;
In the second search, the chart command does not care about the ordering of events.&lt;/P&gt;

&lt;P&gt;Try replacing the last two lines of your first search with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | stats count by date_wday,sort_field
 | sort sort_field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will keep the sort_field available.&lt;/P&gt;

&lt;P&gt;Alternatively, run the chart/stats command first and afterwards the eval+sort commands:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| ...
| stats count by date_wday
| eval sort_field=case(date_wday=="monday",1, date_wday=="tuesday",2, date_wday=="wednesday",3, date_wday=="thursday",4, date_wday=="friday",5, date_wday=="weekend",6)
| sort sort_field | fields - sort_field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;On a side note: Are you sure that events such as date_wday="weekend" exist? Because I am seeing date_wday="sunday" in my Splunk.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:21:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421137#M174237</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2020-09-29T22:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: In the following searches, how come the days of the week are not sorting correctly?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421138#M174238</link>
      <description>&lt;P&gt;not sure for last question. anyway I solved the problem as I do sorting at last after chart, a way more efficient.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 19:22:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421138#M174238</guid>
      <dc:creator>net1993</dc:creator>
      <dc:date>2018-12-12T19:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: In the following searches, how come the days of the week are not sorting correctly?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421139#M174239</link>
      <description>&lt;P&gt;I meant that the condition date_wday=="weekend" will never be met.&lt;BR /&gt;
You might want to change it to case(..., date_wday=="friday",5, date_wday=="saturday",6, date_wday=="sunday",7).&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:21:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421139#M174239</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2020-09-29T22:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: In the following searches, how come the days of the week are not sorting correctly?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421140#M174240</link>
      <description>&lt;P&gt;Your're correct. I had change it and no idea where it did come from. Think I have coppied from somewhere else and probably there was not needed to have weekenend days..&lt;/P&gt;</description>
      <pubDate>Thu, 13 Dec 2018 07:20:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421140#M174240</guid>
      <dc:creator>net1993</dc:creator>
      <dc:date>2018-12-13T07:20:57Z</dc:date>
    </item>
    <item>
      <title>Re: In the following searches, how come the days of the week are not sorting correctly?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421141#M174241</link>
      <description>&lt;P&gt;Solution to that problem are so far 2:&lt;BR /&gt;
1. eval and sort after chart as chart is changing to string&lt;BR /&gt;
2. use another function instead of case to convert the week number to char because when already in char, the sorting is correct.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;tip sorting after chart is way more efficient &lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Thu, 13 Dec 2018 07:24:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/In-the-following-searches-how-come-the-days-of-the-week-are-not/m-p/421141#M174241</guid>
      <dc:creator>net1993</dc:creator>
      <dc:date>2018-12-13T07:24:48Z</dc:date>
    </item>
  </channel>
</rss>

