<?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: Previous business / week day in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Previous-business-week-day/m-p/73586#M18448</link>
    <description>&lt;P&gt;This solution was sent to me by Lincoln at Splunk:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="*Security" earliest=-3d@d latest=@d 
| eval day_value = case(date_wday=="saturday", "0", date_wday="sunday", "0", date_wday=="monday", "1", date_wday== "tuesday", "2", date_wday=="wednesday", "3", date_wday=="thursday","4", date_wday=="friday", "5") 
| eventstats max(day_value) as high_value 
| where day_value=high_value
| eventstats count as "EventCount" by EventCode 
| table EventCode EventCodeDescription EventCount 
| sort EventCode 
| dedup EventCode
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;earliest=-3d@d latest=@d&lt;/CODE&gt; = We always have to go back 3 days to pick up Friday when it's Monday.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eval day_value = case(date_wday=="saturday", "0", date_wday="sunday", "0", date_wday=="monday", "1", date_wday== "tuesday", "2", date_wday=="wednesday", "3", date_wday=="thursday","4", date_wday=="friday", "5")&lt;/CODE&gt; =  Splunk stores the day of the week (in lowercase) as a meta field for every event. Here, we're just setting numeric values into a field called day_value which allows us to differentiate and ultimately code events from the previous business day. Saturday and Sunday are given values of zero. We need decrementing values for the other days of the week, so we can distinguish the previous day from the two days prior. This was the hardest part for me to figure out. Took a little extra "noodle power."  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eventstats max(day_value) as high_value&lt;/CODE&gt; = The max function of eventstats determines the largest value inserted into the day_value field by the case function above and puts this value into a new field called high_value. If you run the search on Monday, the max value would be 5 which is contained in Friday's events. Remember, eventstats will code every event (including Saturday and Sunday's events with this value in the high_value field).&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;where day_value=high_value&lt;/CODE&gt; = Now, all that's left is to filter out the events that have lower values in the day_value field and we do that easily enough with the where command.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 09:53:28 GMT</pubDate>
    <dc:creator>MBerikcurtis</dc:creator>
    <dc:date>2020-09-28T09:53:28Z</dc:date>
    <item>
      <title>Previous business / week day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Previous-business-week-day/m-p/73584#M18446</link>
      <description>&lt;P&gt;Could you tell me if Splunk has a way of filtering based on previous business day or previous weekday? I’m using &lt;CODE&gt;earliest=-1d@d latest=@d&lt;/CODE&gt; to get results from the previous day but that doesn’t help me on Mondays.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Sep 2011 19:54:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Previous-business-week-day/m-p/73584#M18446</guid>
      <dc:creator>MBerikcurtis</dc:creator>
      <dc:date>2011-09-12T19:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Previous business / week day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Previous-business-week-day/m-p/73585#M18447</link>
      <description>&lt;P&gt;&lt;CODE&gt;@w0&lt;/CODE&gt; as the earliest will snap to the Sunday of the current week, &lt;CODE&gt;@w0+1d&lt;/CODE&gt; would snap to the Monday of the week you are currently on.&lt;BR /&gt;
&lt;CODE&gt;-w@w+1d&lt;/CODE&gt; would snap to the Monday of the previous business week.&lt;BR /&gt;
&lt;CODE&gt;@w5&lt;/CODE&gt; would snap to the closest Friday.&lt;/P&gt;

&lt;P&gt;Below is some detail on SearchTimeModifiers:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/4.2.3/SearchReference/SearchTimeModifiers"&gt;http://docs.splunk.com/Documentation/Splunk/4.2.3/SearchReference/SearchTimeModifiers&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Sep 2011 08:15:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Previous-business-week-day/m-p/73585#M18447</guid>
      <dc:creator>Drainy</dc:creator>
      <dc:date>2011-09-13T08:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: Previous business / week day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Previous-business-week-day/m-p/73586#M18448</link>
      <description>&lt;P&gt;This solution was sent to me by Lincoln at Splunk:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="*Security" earliest=-3d@d latest=@d 
| eval day_value = case(date_wday=="saturday", "0", date_wday="sunday", "0", date_wday=="monday", "1", date_wday== "tuesday", "2", date_wday=="wednesday", "3", date_wday=="thursday","4", date_wday=="friday", "5") 
| eventstats max(day_value) as high_value 
| where day_value=high_value
| eventstats count as "EventCount" by EventCode 
| table EventCode EventCodeDescription EventCount 
| sort EventCode 
| dedup EventCode
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;earliest=-3d@d latest=@d&lt;/CODE&gt; = We always have to go back 3 days to pick up Friday when it's Monday.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eval day_value = case(date_wday=="saturday", "0", date_wday="sunday", "0", date_wday=="monday", "1", date_wday== "tuesday", "2", date_wday=="wednesday", "3", date_wday=="thursday","4", date_wday=="friday", "5")&lt;/CODE&gt; =  Splunk stores the day of the week (in lowercase) as a meta field for every event. Here, we're just setting numeric values into a field called day_value which allows us to differentiate and ultimately code events from the previous business day. Saturday and Sunday are given values of zero. We need decrementing values for the other days of the week, so we can distinguish the previous day from the two days prior. This was the hardest part for me to figure out. Took a little extra "noodle power."  &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;eventstats max(day_value) as high_value&lt;/CODE&gt; = The max function of eventstats determines the largest value inserted into the day_value field by the case function above and puts this value into a new field called high_value. If you run the search on Monday, the max value would be 5 which is contained in Friday's events. Remember, eventstats will code every event (including Saturday and Sunday's events with this value in the high_value field).&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;where day_value=high_value&lt;/CODE&gt; = Now, all that's left is to filter out the events that have lower values in the day_value field and we do that easily enough with the where command.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:53:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Previous-business-week-day/m-p/73586#M18448</guid>
      <dc:creator>MBerikcurtis</dc:creator>
      <dc:date>2020-09-28T09:53:28Z</dc:date>
    </item>
  </channel>
</rss>

