<?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: Detect Start-of-Week &amp; Weekly aggregations in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Detect-Start-of-Week-Weekly-aggregations/m-p/454750#M168185</link>
    <description>&lt;P&gt;One way I figured out how to do this is using: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Week = strftime(strptime(_time, "%Y-%m-%d %H:%M:%S.%N"), "%V")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;strptime&lt;/STRONG&gt; converts the _time [formatted in "%Y-%m-%d %H:%M:%S.%N"] to Unix epoch time. Then &lt;STRONG&gt;strftime&lt;/STRONG&gt; extracts the week of year from the epoch time using "&lt;STRONG&gt;%V&lt;/STRONG&gt;"&lt;/P&gt;

&lt;P&gt;The variable &lt;STRONG&gt;%V&lt;/STRONG&gt; is not mentioned in the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables"&gt;documentation&lt;/A&gt;.  &lt;/P&gt;

&lt;P&gt;However, how do I declare custom weeks, if the business requirements are as such? &lt;/P&gt;</description>
    <pubDate>Wed, 25 Jul 2018 03:25:07 GMT</pubDate>
    <dc:creator>anirbandasdeb</dc:creator>
    <dc:date>2018-07-25T03:25:07Z</dc:date>
    <item>
      <title>Detect Start-of-Week &amp; Weekly aggregations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Detect-Start-of-Week-Weekly-aggregations/m-p/454749#M168184</link>
      <description>&lt;P&gt;Hello splunkers, &lt;/P&gt;

&lt;P&gt;We have to calculate some KPIs, on time-series data, aggregated by multiple factors, with time being the most important one. &lt;BR /&gt;
The most common time aggregations for us are monthly and weekly. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Scenario:&lt;/STRONG&gt; Calculate the weekly trend of a KPI for the month of May 2018 [ref image attached]&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5411iEEDF346ABB20F58A/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;How one would normally do it would be [assume week start on Sunday]: &lt;BR /&gt;
&lt;STRONG&gt;Week  Date&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;1:&lt;/STRONG&gt;        1 - 5&lt;BR /&gt;
&lt;STRONG&gt;2:&lt;/STRONG&gt;        6 - 12&lt;BR /&gt;
&lt;STRONG&gt;3:&lt;/STRONG&gt;        13 - 19&lt;BR /&gt;
&lt;STRONG&gt;4:&lt;/STRONG&gt;        20 - 26&lt;BR /&gt;
&lt;STRONG&gt;5:&lt;/STRONG&gt;        27 - 31&lt;/P&gt;

&lt;P&gt;Thus there will be 5 data points. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;How do I implement this in Splunk?&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;The way I figured out to do it now is use "&lt;STRONG&gt;bin span=1w _time&lt;/STRONG&gt;", but it does not detect the &lt;EM&gt;week start&lt;/EM&gt;. &lt;BR /&gt;
However, this approach plainly takes 7 days from the 1st of the month and the result is that we have skewed weeks leading to misleading KPI values. &lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 08:02:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Detect-Start-of-Week-Weekly-aggregations/m-p/454749#M168184</guid>
      <dc:creator>anirbandasdeb</dc:creator>
      <dc:date>2018-07-24T08:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Detect Start-of-Week &amp; Weekly aggregations</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Detect-Start-of-Week-Weekly-aggregations/m-p/454750#M168185</link>
      <description>&lt;P&gt;One way I figured out how to do this is using: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval Week = strftime(strptime(_time, "%Y-%m-%d %H:%M:%S.%N"), "%V")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;strptime&lt;/STRONG&gt; converts the _time [formatted in "%Y-%m-%d %H:%M:%S.%N"] to Unix epoch time. Then &lt;STRONG&gt;strftime&lt;/STRONG&gt; extracts the week of year from the epoch time using "&lt;STRONG&gt;%V&lt;/STRONG&gt;"&lt;/P&gt;

&lt;P&gt;The variable &lt;STRONG&gt;%V&lt;/STRONG&gt; is not mentioned in the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables"&gt;documentation&lt;/A&gt;.  &lt;/P&gt;

&lt;P&gt;However, how do I declare custom weeks, if the business requirements are as such? &lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 03:25:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Detect-Start-of-Week-Weekly-aggregations/m-p/454750#M168185</guid>
      <dc:creator>anirbandasdeb</dc:creator>
      <dc:date>2018-07-25T03:25:07Z</dc:date>
    </item>
  </channel>
</rss>

