<?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: Find variance between current hour value and avg value of same hour over last 2 weeks in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/650891#M225042</link>
    <description>&lt;P&gt;Instead of using multiple virtually identical (apart from time range) appended searches, just do one longer search and use timewrap.&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jul 2023 20:43:54 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2023-07-17T20:43:54Z</dc:date>
    <item>
      <title>Find variance between current hour value and avg value of same hour over last 2 weeks</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/650888#M225041</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have an search that is used on a dashboard that I would like tweaked.&lt;/P&gt;&lt;P&gt;Currently this search/panel displays the variance of current hour over the same hour the week before. for example: The value at hour 10 on Wed 7/19/23 will be compared to the value at hour 10 on Wed 7/12/23 and give variance.&lt;/P&gt;&lt;P&gt;Instead, I would like to compare current hour value to the value of the AVG of that same hour over the last 2 weeks (instead of compared to 1 day). For example I would like hour 10 on Wed 7/19/23 to be compared to the avg of hour 10 each day from Tues 7/18/23 to Wed 7/5/23.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="bryhoffman_0-1689622678784.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/26307i58FDC6F8D5C69B64/image-size/medium?v=v2&amp;amp;px=400" role="button" title="bryhoffman_0-1689622678784.png" alt="bryhoffman_0-1689622678784.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Current search:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count where index=msexchange host=SMEXCH13* earliest=-14d@d latest=-13d@d by _time span=1h
| eval hour=strftime(_time,"%H")
| eval ReportKey="2weekprior"
| stats values(count) as count by hour, ReportKey
| append
[| tstats count where index=msexchange host=SMEXCH13* earliest=-7d@d latest=-6d@d by _time span=1h
| eval hour=strftime(_time,"%H")
| eval ReportKey="1weekprior"
| stats values(count) as count by hour, ReportKey ]
| append
[| tstats count where index=msexchange host=SMEXCH13* earliest=-0d@d latest=-0h@h by _time span=1h
| eval hour=strftime(_time,"%H")
| eval ReportKey="currentweek"
| stats values(count) as count by hour, ReportKey ]
| eval currenthour=strftime(_time,"%H")
| xyseries hour, ReportKey, count
| eval nowhour = strftime(now(),"%H")
| eval comparehour = nowhour-1
|where hour&amp;lt;=comparehour
|sort by -hour
| table hour,nowhour,comparehour, currentweek,1weekprior,2weekprior
|eval 1weekvar = currentweek/'1weekprior'
|eval 2weekvar = currentweek/'2weekprior'
|eval variance=round(((('1weekvar'+'2weekvar')/2)*100)-100,2)
|table hour,variance
|head 5&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 04 Mar 2024 05:59:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/650888#M225041</guid>
      <dc:creator>bryhoffman</dc:creator>
      <dc:date>2024-03-04T05:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: Find variance between current hour value and avg value of same hour over last 2 weeks</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/650891#M225042</link>
      <description>&lt;P&gt;Instead of using multiple virtually identical (apart from time range) appended searches, just do one longer search and use timewrap.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 20:43:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/650891#M225042</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-07-17T20:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: Find variance between current hour value and avg value of same hour over last 2 weeks</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/650892#M225043</link>
      <description>&lt;P&gt;Could you show me what you mean? Thanks for the quick reply&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2023 21:07:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/650892#M225043</guid>
      <dc:creator>bryhoffman</dc:creator>
      <dc:date>2023-07-17T21:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find variance between current hour value and avg value of same hour over last 2 weeks</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/650915#M225052</link>
      <description>&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/9.1.0/SearchReference/Timewrap" target="_self"&gt;https://docs.splunk.com/Documentation/Splunk/9.1.0/SearchReference/Timewrap&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jul 2023 05:46:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/650915#M225052</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-07-18T05:46:14Z</dc:date>
    </item>
    <item>
      <title>Re: Find variance between current hour value and avg value of same hour over last 2 weeks</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/679355#M232235</link>
      <description>&lt;P&gt;Bump.&amp;nbsp; I am working the exact same scenario.&lt;/P&gt;&lt;P&gt;Transaction volume is a daily bell curve, so comparing volume from 16:00 to&amp;nbsp;15:00 is useless.&amp;nbsp; Tran volumes will always be increasing or decreasing hour by hour.&lt;/P&gt;&lt;P&gt;Transaction volume is a daily bell curve, so comparing today at 16:00 to the average of the last 24 hours is useless.&amp;nbsp; 24 hour average might be 1M per hour, but 24 hour deviation might be + or - 50%.&lt;/P&gt;&lt;P&gt;Transaction volume is also a weekly bell curve, so comparing today's 16:00 traffic to JUST yesterday's 16:00 traffic is okay, but still not great.&lt;BR /&gt;&lt;BR /&gt;Best case is exact scenario OP described:&lt;/P&gt;&lt;P class="lia-indent-padding-left-30px"&gt;Compare today's 16:00-17:00 traffic to the AVERAGE of the last 7 or 14&amp;nbsp;days' 16:00-17:00 traffic and then alert based on a variance.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Mar 2024 23:47:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/679355#M232235</guid>
      <dc:creator>Cottonball</dc:creator>
      <dc:date>2024-03-01T23:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find variance between current hour value and avg value of same hour over last 2 weeks</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/679358#M232237</link>
      <description>&lt;P&gt;I know it's half year later, but the answer is still &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Timewrap" target="_blank" rel="noopener"&gt;timewrap&lt;/A&gt; as&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;indicated. &amp;nbsp;Using OP's sample search,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count where index=msexchange host=SMEXCH13* earliest=-14d@d latest=-0d@d by _time span=1h 
| timechart span=1h values(count) as count
| timewrap 1w@w
| eval _time = strftime(_time, "%H")
| transpose 0 column_name=week header_field=_time
| search week != _*
| stats var(*) as *
| transpose column_name=hour
| rename "row 1" AS variance&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Note you also don't need to manually calculate variance from scratch. &amp;nbsp;Splunk stats has &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Aggregatefunctions#var.28.26lt.3Bvalue.26gt.3B.29" target="_blank" rel="noopener"&gt;var&lt;/A&gt;&amp;nbsp;function.)&amp;nbsp;Obviously I do not have the same exchange data, but this can easily be simulated with index=_internal. &amp;nbsp;My results are&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;hour&lt;/TD&gt;&lt;TD&gt;variance&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00&lt;/TD&gt;&lt;TD&gt;15664.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;01&lt;/TD&gt;&lt;TD&gt;72200&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;02&lt;/TD&gt;&lt;TD&gt;15488&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;03&lt;/TD&gt;&lt;TD&gt;63368&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;04&lt;/TD&gt;&lt;TD&gt;14792&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;05&lt;/TD&gt;&lt;TD&gt;51842&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;06&lt;/TD&gt;&lt;TD&gt;31752&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;07&lt;/TD&gt;&lt;TD&gt;69192&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;08&lt;/TD&gt;&lt;TD&gt;41123380.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;09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P&gt;Simulation code is simply&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count where index=_internal earliest=-14d@d latest=-0d@d by _time span=1h@h
| timechart span=1h values(count) as count
| timewrap 1w@w
| eval _time = strftime(_time, "%H")
| transpose 0 column_name=week header_field=_time
| search week != _*
| stats var(*) as *
| transpose column_name=hour
| rename "row 1" AS variance&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Mar 2024 01:18:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/679358#M232237</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-03-02T01:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Find variance between current hour value and avg value of same hour over last 2 weeks</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/679438#M232278</link>
      <description>&lt;P class="lia-align-left"&gt;Being somewhat of a journeyman myself, the proper way to use timewrap was a bit of a mystery to me.&amp;nbsp; So, while the answer may be apparent to many, I was not sure how to wield the information.&lt;BR /&gt;&lt;BR /&gt;Thank you for the response.&amp;nbsp; I will give it a go on Monday.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Mar 2024 02:21:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-variance-between-current-hour-value-and-avg-value-of-same/m-p/679438#M232278</guid>
      <dc:creator>Cottonball</dc:creator>
      <dc:date>2024-03-04T02:21:14Z</dc:date>
    </item>
  </channel>
</rss>

