<?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: Ignore empty data point when calculating average in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173890#M49899</link>
    <description>&lt;P&gt;Using fillnull value=NULL seems to ignore any columns that have NULL in them.&lt;/P&gt;</description>
    <pubDate>Thu, 07 May 2015 14:00:27 GMT</pubDate>
    <dc:creator>ermosk</dc:creator>
    <dc:date>2015-05-07T14:00:27Z</dc:date>
    <item>
      <title>Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173881#M49890</link>
      <description>&lt;P&gt;I am trying to calculate the average for a few columns and rows but I have came across the following issue. Some rows might not have data for a particular column, but it seems these are still taken into account when calculating the avg for this column which means the data is way off. I'd like my formula to ignore a data point (if not present) when calculating the average for the column.&lt;/P&gt;

&lt;P&gt;Here is my formula :&lt;/P&gt;

&lt;P&gt;table ABC* | stats avg(ABC_*) &lt;/P&gt;

&lt;P&gt;So if I have something like :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Column : ABC_1 | ABC_2 | ABC_3 | ABC_4 | ABC_5
          1        2       1        2      2  
          2                2               1             
          1                2        3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The average for column ABC_2, ABC_4 and ABC_5 is incorrect. &lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:45:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173881#M49890</guid>
      <dc:creator>ermosk</dc:creator>
      <dc:date>2020-09-28T19:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173882#M49891</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;table ABC* | stats count(ABC*) AS countABC*, sum(ABC*) AS sumABC* | eval avg*=sumABC*/countABC*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2015 12:08:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173882#M49891</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-07T12:08:41Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173883#M49892</link>
      <description>&lt;P&gt;Use fillnull to provide values for NULL and try.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 12:56:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173883#M49892</guid>
      <dc:creator>srinathd</dc:creator>
      <dc:date>2015-05-07T12:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173884#M49893</link>
      <description>&lt;P&gt;I'm not sure that the problem is the &lt;STRONG&gt;avg&lt;/STRONG&gt; function. Because the avg function returns the average of the values of field &lt;STRONG&gt;X&lt;/STRONG&gt;. Means the null value of the field X is not taking  into account by avg(X). In another words, in your table, avg(ABC_2) must return 2.&lt;BR /&gt;
Check the problem elsewhere&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 13:02:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173884#M49893</guid>
      <dc:creator>stephanefotso</dc:creator>
      <dc:date>2015-05-07T13:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173885#M49894</link>
      <description>&lt;P&gt;I like this approach but I can't get it to work. I get the following error:&lt;/P&gt;

&lt;P&gt;Error in 'eval' command: The expression is malformed. An unexpected character is reached at '/count_*'.&lt;/P&gt;

&lt;P&gt;Here is how my search currently looks&lt;/P&gt;

&lt;P&gt;Some initial event filtering | table time_svc_agg* | stats count(time_svc_agg_&lt;EM&gt;) AS count_&lt;/EM&gt;, sum(time_svc_agg_&lt;EM&gt;) AS sum_&lt;/EM&gt; | eval avg_&lt;EM&gt;=sum_&lt;/EM&gt;/count_*&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:45:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173885#M49894</guid>
      <dc:creator>ermosk</dc:creator>
      <dc:date>2020-09-28T19:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173886#M49895</link>
      <description>&lt;P&gt;It's quite simple really. Looking at the table I can clearly see what the result should be. Just adding the &lt;STRONG&gt;avg&lt;/STRONG&gt; function causes it go off.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 13:14:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173886#M49895</guid>
      <dc:creator>ermosk</dc:creator>
      <dc:date>2015-05-07T13:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173887#M49896</link>
      <description>&lt;P&gt;I encapsulated them in $$ (like  eval avg_&lt;EM&gt;=$sum_&lt;/EM&gt;$/$count_*$ ) but I still cant see any new columns with avg_ in my table&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:45:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173887#M49896</guid>
      <dc:creator>ermosk</dc:creator>
      <dc:date>2020-09-28T19:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173888#M49897</link>
      <description>&lt;P&gt;It looks like you will have to iterate each variable as you need it in the "eval" part like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| table time_svc_agg* | stats count(time_svc_agg_*) AS count_*, sum(time_svc_agg_*) AS sum_* | eval avg_1=sum_1/count_1 | eval avg_2=sum_2/count_2 ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2015 13:26:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173888#M49897</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-07T13:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173889#M49898</link>
      <description>&lt;P&gt;So this introduces a new issue because I don't know beforehand how many of these time_svc_agg will exist, nor their names. Will I need a subquery to take care of this?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:45:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173889#M49898</guid>
      <dc:creator>ermosk</dc:creator>
      <dc:date>2020-09-28T19:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173890#M49899</link>
      <description>&lt;P&gt;Using fillnull value=NULL seems to ignore any columns that have NULL in them.&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 14:00:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173890#M49899</guid>
      <dc:creator>ermosk</dc:creator>
      <dc:date>2015-05-07T14:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Ignore empty data point when calculating average</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173891#M49900</link>
      <description>&lt;P&gt;Did you ever find a solution for this? I was doing what woodcock suggested in his reply to your question, but this rounds to a lower precision than the avg function.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Sep 2018 22:19:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Ignore-empty-data-point-when-calculating-average/m-p/173891#M49900</guid>
      <dc:creator>asturt</dc:creator>
      <dc:date>2018-09-26T22:19:58Z</dc:date>
    </item>
  </channel>
</rss>

