<?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: Why does the Average Event Count not calculate properly after using the &amp;quot;join&amp;quot; command in my search? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240384#M71440</link>
    <description>&lt;P&gt;Not sure why it is not giving you desired results. I have tested your queries and they work fine.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jan 2017 22:59:08 GMT</pubDate>
    <dc:creator>nabeel652</dc:creator>
    <dc:date>2017-01-18T22:59:08Z</dc:date>
    <item>
      <title>Why does the Average Event Count not calculate properly after using the "join" command in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240383#M71439</link>
      <description>&lt;P&gt;Here is the search that I am attempting: &lt;EM&gt;(Intended outcome:  compare login successes from a 24 hour period to an average of login successes over a 30 day period.  Complication:  logs are stamped with UTC)&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;index=myindex type=user_auth acct=admin OR acct=temp res=success earliest=-24h &lt;BR /&gt;
| eval local_date_hour = strftime(_time, "%H") &lt;EM&gt;(adjustment for logs stamped with UTC)&lt;/EM&gt;&lt;BR /&gt;
| stats count as Recent_Event_count by local_date_hour&lt;BR /&gt;
|** join** local_date_hour [search type=user_auth acct=admin OR acct=temp res=success earliest=-30d@d&lt;BR /&gt;
| eval local_date_hour = strftime(_time, "%H") &lt;EM&gt;(adjustment for logs stamped with UTC)&lt;/EM&gt;&lt;BR /&gt;
| stats count by local_date_hour&lt;BR /&gt;
| addinfo&lt;BR /&gt;
| eval days = round((info_max_time-info_min_time) / 86400) &lt;BR /&gt;
| eval Average_Event_Count = round(count / days, 2)]&lt;BR /&gt;
| fields local_date_hour, Average_Event_Count, Recent_Event_Count &lt;BR /&gt;
| sort +local_date_hour &lt;/P&gt;

&lt;P&gt;For some reason the "Average_Event_Count" is not calculating properly.  For example if my Recent_Event_Count for hour 1 is 39766, the Average_Event_Count is showing 12022.07, which is a fraction of the anticipated results.&lt;/P&gt;

&lt;P&gt;If I remove the join and perform each of the searches separately, expected results are returned for each count.  This leads me to believe that the join is causing an issue.&lt;/P&gt;

&lt;P&gt;I should also note that I am using a very similar search (without adjustments for UTC)  for other dashboard panels and it seems to be calculating as expected.  Even if I remove the adjustment for UTC, the problem remains.   I am hoping there is an uncomplicated answer as I am a new user &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:27:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240383#M71439</guid>
      <dc:creator>cc3658</dc:creator>
      <dc:date>2020-09-29T12:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the Average Event Count not calculate properly after using the "join" command in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240384#M71440</link>
      <description>&lt;P&gt;Not sure why it is not giving you desired results. I have tested your queries and they work fine.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 22:59:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240384#M71440</guid>
      <dc:creator>nabeel652</dc:creator>
      <dc:date>2017-01-18T22:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the Average Event Count not calculate properly after using the "join" command in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240385#M71441</link>
      <description>&lt;P&gt;1) You should select your events on an hour and a day boundary, respectively.&lt;BR /&gt;&lt;BR /&gt;
2) watch your capitalization.  Recent_event_count is capitalized two different ways in your code.&lt;BR /&gt;
3) just in case there was anything odd about the results of addinfo, I just summed by date &lt;/P&gt;

&lt;P&gt;Try this - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex type=user_auth acct=admin OR acct=temp res=success 
earliest=-24h latest=@h
| eval local_date_hour = strftime(_time, "%H") 
| stats count as Recent_Event_Count by local_date_hour
| join local_date_hour 

   [ search type=user_auth acct=admin OR acct=temp res=success 
     earliest=-30d@d latest=@d
   | eval local_date_hour = strftime(_time, "%H") 
   | eval local_date = relative_time(_time, "@d") 
   | stats count as HourlyCount by local_date_hour local_date
   | stats dc(local_date) as days, sum(HourlyCount) as HourlyCount by local_date_hour
   | eval Average_Event_Count = round(HourlyCount / days, 2)
   | fields local_date_hour Average_Event_Count
   ]

| fields local_date_hour, Average_Event_Count, Recent_Event_Count 
| sort 0 +local_date_hour
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;edited to use sort 0 instead of sort in case there were more than 100 values to be sorted.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 12:28:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240385#M71441</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-09-29T12:28:31Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the Average Event Count not calculate properly after using the "join" command in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240386#M71442</link>
      <description>&lt;P&gt;Although it occurs to me that since you have no need of knowing the number of days that went into the calculation, the middle subsearch part can be simplified to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=myindex type=user_auth acct=admin OR acct=temp res=success 
 earliest=-24h latest=@h
 | eval local_date_hour = strftime(_time, "%H") 
 | stats count as Recent_Event_Count by local_date_hour
 | join local_date_hour 

       [ search type=user_auth acct=admin OR acct=temp res=success 
         earliest=-30d@d latest=@d
       | eval local_date_hour = strftime(_time, "%H") 
       | eval local_date = relative_time(_time, "@d") 
       | stats count as HourlyCount by local_date_hour local_date
       | stats avg(HourlyCount) as Average_Event_Count by local_date_hour
       | eval Average_Event_Count = round(Average_Event_Count, 2)
       ]

 | fields local_date_hour, Average_Event_Count, Recent_Event_Count 
 | sort 0 +local_date_hour
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;edited to use sort 0 instead of sort in case there were more than 100 values to be sorted.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2017 23:32:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240386#M71442</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-01-18T23:32:07Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the Average Event Count not calculate properly after using the "join" command in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240387#M71443</link>
      <description>&lt;P&gt;DalJeanis,&lt;BR /&gt;
I have tested your suggested query against my data and it appears to be returning the expected results.  Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 14:25:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240387#M71443</guid>
      <dc:creator>cc3658</dc:creator>
      <dc:date>2017-01-20T14:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the Average Event Count not calculate properly after using the "join" command in my search?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240388#M71444</link>
      <description>&lt;P&gt;You are quite welcome!  It was a fun challenge.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2017 15:35:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-does-the-Average-Event-Count-not-calculate-properly-after/m-p/240388#M71444</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-01-20T15:35:03Z</dc:date>
    </item>
  </channel>
</rss>

