<?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: Stats avg() to include zero values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Stats-avg-to-include-zero-values/m-p/53287#M12960</link>
    <description>&lt;P&gt;That probably doesn't represent your data. stats avg works perfectly fine on what you posted.  &lt;/P&gt;

&lt;P&gt;Are you sure that the real data doesn't contain a NULL value for the numerical field ?&lt;/P&gt;

&lt;P&gt;Example with NULL data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | head 2 | eval user="john" | streamstats count as count| eval num=if(count==2,20,NULL) | table user num | eventstats avg(num) as avg by user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With non-null-data :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | head 2 | eval user="john" | streamstats count as count| eval num=if(count==2,20,0) | table user num | eventstats avg(num) as avg by user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You want to look at &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.4/SearchReference/Fillnull"&gt;fillnull&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Sep 2013 12:01:40 GMT</pubDate>
    <dc:creator>jonuwz</dc:creator>
    <dc:date>2013-09-03T12:01:40Z</dc:date>
    <item>
      <title>Stats avg() to include zero values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-avg-to-include-zero-values/m-p/53286#M12959</link>
      <description>&lt;P&gt;Hi I'm trying to calculate the average number of requests for a user, lets say user1 across the space of a week.  Lets say the data is&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Sun user1 0
Mon user 5
Tue user1 5
Wed user1 0
Thu user1 10
Fri user1 0
Sat user1 0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I do:&lt;/P&gt;

&lt;P&gt;... | stats avg(Requests) by user&lt;/P&gt;

&lt;P&gt;I get 6.66, which is correct if I'm only counting three values.  But I want to include values where the number of requests is zero.  So the real sum should be (0+5+5+0+10+0+0)/7 = 2.85.&lt;/P&gt;

&lt;P&gt;How do I get stats to include the zeros?&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2013 10:28:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-avg-to-include-zero-values/m-p/53286#M12959</guid>
      <dc:creator>malcolmtkelly</dc:creator>
      <dc:date>2013-09-03T10:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Stats avg() to include zero values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-avg-to-include-zero-values/m-p/53287#M12960</link>
      <description>&lt;P&gt;That probably doesn't represent your data. stats avg works perfectly fine on what you posted.  &lt;/P&gt;

&lt;P&gt;Are you sure that the real data doesn't contain a NULL value for the numerical field ?&lt;/P&gt;

&lt;P&gt;Example with NULL data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | head 2 | eval user="john" | streamstats count as count| eval num=if(count==2,20,NULL) | table user num | eventstats avg(num) as avg by user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;With non-null-data :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | head 2 | eval user="john" | streamstats count as count| eval num=if(count==2,20,0) | table user num | eventstats avg(num) as avg by user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You want to look at &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0.4/SearchReference/Fillnull"&gt;fillnull&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2013 12:01:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-avg-to-include-zero-values/m-p/53287#M12960</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-09-03T12:01:40Z</dc:date>
    </item>
  </channel>
</rss>

