<?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: Calculate average count by hour &amp; day combined in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculate-average-count-by-hour-day-combined/m-p/459953#M129771</link>
    <description>&lt;P&gt;It would help if you posted a sample event, as I think you're being a needlessly complex with the timestamp wrangling. That said, what I think you should do is create a field for  the day-hour and a field for the day, then throw in a couple of eventstats  to get the average per day. Here's a run anywhere example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  gentimes start=01/01/2017 end=12/30/2017 increment=1h
|  eval dow_hour=strftime(starttime,"%a-%H"), dow=strftime(starttime,"%a")
|  fields dow dow_hour
|  eventstats count as total_events
|  eventstats count(eval(match(dow_hour,"00"))) as dows by dow
|  eval avg=total_events/dows
|  stats count as events_by_dow_hour max(avg) as average_events_by_dow max(dows) as dows max(total_events)  by dow_hour dow
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These will more or less all be the same because I've just done one event per hour - but throw that at your data and you should see something relevant. Note eventstats can get hairy on large events sets - you may be better off appending multiple stats searches together. If the result set is not to large its perfectly safe. &lt;/P&gt;</description>
    <pubDate>Thu, 26 Jul 2018 12:16:57 GMT</pubDate>
    <dc:creator>jplumsdaine22</dc:creator>
    <dc:date>2018-07-26T12:16:57Z</dc:date>
    <item>
      <title>Calculate average count by hour &amp; day combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-average-count-by-hour-day-combined/m-p/459951#M129769</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am wanting to calculate the average count of "incidents" per hour/day (i.e. Mon-07:00, Mon-08:00) over a 12 month period. I am using a date field that is not my timestamp. This is the syntax I have so far, any help would be appreciated.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=sourcetype1
| eval log_day=strftime(strptime(DATE_ENTERED,"%Y-%m-%d %H:%M"),"%a-%H:00")
| eval sort_field=case(log_day LIKE "%Mon%",1, log_day LIKE "%Tues%",2, log_day LIKE "%Wed%",3, log_day LIKE "%Thu%",4, log_day LIKE "%Fri%",5, log_day LIKE "%Sat%",6, log_day LIKE "%Sun%",7) 
 | stats count by log_day sort_field
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So essentially at the moment this search is telling how many incidents I have had in total for Mon-07:00 etc. but I need the average amount per day across the 12 month window. The sort field is only there to ensure the days of the week are in order (Mon to Sun).&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jul 2018 10:59:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-average-count-by-hour-day-combined/m-p/459951#M129769</guid>
      <dc:creator>jackreeves</dc:creator>
      <dc:date>2018-07-26T10:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average count by hour &amp; day combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-average-count-by-hour-day-combined/m-p/459952#M129770</link>
      <description>&lt;P&gt;@jackreeves &lt;/P&gt;

&lt;P&gt;Give a try with below query..&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
|eval weekdata=mvappend("2018-07-22 13:09:04","2018-07-22 12:09:04","2018-07-22 01:09:04","2018-07-22 20:09:04","2018-07-22 21:09:04","2018-07-22 22:09:04","2018-07-22 23:09:04","2018-07-22 24:09:04","2018-07-23 13:09:04","2018-07-24 13:09:04","2018-07-25 13:09:04","2018-07-26 13:09:04","2018-07-27 13:09:04","2018-07-28 13:09:04","2018-07-29 13:09:04","2018-07-30 13:09:04")
| mvexpand weekdata
| eval week_hours =  strftime(strptime(weekdata, "%Y-%m-%d %H" ), "%H")
| eval week =  strftime(strptime(weekdata, "%Y-%m-%d" ), "%A")
| eval week_in_number =  strftime(strptime(weekdata, "%Y-%m-%d" ), "%w") 
| eval data_forcount=case(week_hours=13 AND weekdata="2018-07-22 13:09:04",13,week_hours=12 AND weekdata="2018-07-22 12:09:04",12,week_hours=13,10) 
| stats avg(data_forcount) as data_forcount,values(week_in_number) as week_in_number by week,week_hours
|  sort week_in_number
| table week,week_hours,data_forcount
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
Shankarananth&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jul 2018 11:36:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-average-count-by-hour-day-combined/m-p/459952#M129770</guid>
      <dc:creator>Shan</dc:creator>
      <dc:date>2018-07-26T11:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average count by hour &amp; day combined</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-average-count-by-hour-day-combined/m-p/459953#M129771</link>
      <description>&lt;P&gt;It would help if you posted a sample event, as I think you're being a needlessly complex with the timestamp wrangling. That said, what I think you should do is create a field for  the day-hour and a field for the day, then throw in a couple of eventstats  to get the average per day. Here's a run anywhere example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  gentimes start=01/01/2017 end=12/30/2017 increment=1h
|  eval dow_hour=strftime(starttime,"%a-%H"), dow=strftime(starttime,"%a")
|  fields dow dow_hour
|  eventstats count as total_events
|  eventstats count(eval(match(dow_hour,"00"))) as dows by dow
|  eval avg=total_events/dows
|  stats count as events_by_dow_hour max(avg) as average_events_by_dow max(dows) as dows max(total_events)  by dow_hour dow
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These will more or less all be the same because I've just done one event per hour - but throw that at your data and you should see something relevant. Note eventstats can get hairy on large events sets - you may be better off appending multiple stats searches together. If the result set is not to large its perfectly safe. &lt;/P&gt;</description>
      <pubDate>Thu, 26 Jul 2018 12:16:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-average-count-by-hour-day-combined/m-p/459953#M129771</guid>
      <dc:creator>jplumsdaine22</dc:creator>
      <dc:date>2018-07-26T12:16:57Z</dc:date>
    </item>
  </channel>
</rss>

