<?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: Sum to have a value as zero in case not found in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355145#M105073</link>
    <description>&lt;P&gt;I have the above as a part of biq search query so can't add it.  My complete query has the below as a two columns in appendcols.&lt;/P&gt;

&lt;P&gt;Search ns=app1 Error | stats sum(eval(AcctNo="'1000394'")) as "FailedOccurences" sum(eval(AcctNo!="'1000394'")) as "SuccessOccurences" &lt;/P&gt;

&lt;P&gt;Please let me know how to get the value of 0 for Failed and Success Occureances if not found.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 22 Sep 2017 19:23:42 GMT</pubDate>
    <dc:creator>kdulhan</dc:creator>
    <dc:date>2017-09-22T19:23:42Z</dc:date>
    <item>
      <title>Sum to have a value as zero in case not found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355141#M105069</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;I have some search criteria followed by stats as:&lt;/P&gt;

&lt;P&gt;Search ns=app1 Error | stats sum(eval(AcctNo="'1000394'")) as "FailedOccurences".&lt;/P&gt;

&lt;P&gt;In case if that AcctNo is not found in the Search, it does not display FailedOccurences.&lt;/P&gt;

&lt;P&gt;Kindly let me how can I get a value of Zero for FailedOccurences if AcctNo is not found in Search result.&lt;/P&gt;

&lt;P&gt;Thank you. &lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 15:59:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355141#M105069</guid>
      <dc:creator>kdulhan</dc:creator>
      <dc:date>2017-09-22T15:59:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sum to have a value as zero in case not found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355142#M105070</link>
      <description>&lt;P&gt;add &lt;CODE&gt;|appendpipe [stats count|where count==0|eval FailedOccurences=0|table FailedOccurences]&lt;/CODE&gt; to the end of your search&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 16:09:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355142#M105070</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-09-22T16:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sum to have a value as zero in case not found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355143#M105071</link>
      <description>&lt;P&gt;Try this!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats sum(eval(if(AcctNo="'1000394'",1,0))) as "FailedOccurences"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;※In the case of SUM, please set the items you want to total.&lt;BR /&gt;
1-&amp;gt;your field name&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 16:18:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355143#M105071</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2017-09-22T16:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sum to have a value as zero in case not found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355144#M105072</link>
      <description>&lt;P&gt;The above is not displaying a column "FailedOccureances".&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 19:19:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355144#M105072</guid>
      <dc:creator>kdulhan</dc:creator>
      <dc:date>2017-09-22T19:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Sum to have a value as zero in case not found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355145#M105073</link>
      <description>&lt;P&gt;I have the above as a part of biq search query so can't add it.  My complete query has the below as a two columns in appendcols.&lt;/P&gt;

&lt;P&gt;Search ns=app1 Error | stats sum(eval(AcctNo="'1000394'")) as "FailedOccurences" sum(eval(AcctNo!="'1000394'")) as "SuccessOccurences" &lt;/P&gt;

&lt;P&gt;Please let me know how to get the value of 0 for Failed and Success Occureances if not found.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 19:23:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355145#M105073</guid>
      <dc:creator>kdulhan</dc:creator>
      <dc:date>2017-09-22T19:23:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sum to have a value as zero in case not found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355146#M105074</link>
      <description>&lt;P&gt;since you have a column for FailedOccurences and SuccessOccurences, try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...|appendpipe [stats count(FailedOccurences) as count|where count==0|eval FailedOccurences=0|table FailedOccurences]|stats values(*) as *
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if your final output is just those two queries, adding this appendpipe at the end should work.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 19:45:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355146#M105074</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-09-22T19:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sum to have a value as zero in case not found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355147#M105075</link>
      <description>&lt;P&gt;| stats sum(eval(if(user=="1000394",1,0))) as FailedOccurences by AcctNo&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2017 20:19:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355147#M105075</guid>
      <dc:creator>sbbadri</dc:creator>
      <dc:date>2017-09-22T20:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: Sum to have a value as zero in case not found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355148#M105076</link>
      <description>&lt;P&gt;For me, none of the previous answers worked due to the nature of my summary query that I'm getting as input. Nonetheless, the problem still boiled down to the fact that my " &lt;CODE&gt;| stats sum(count) as myVariable&lt;/CODE&gt; " resulted in null instead of 0. The fix that worked for me was to replace that naive sum with the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats sum(count) as myVariableSum, count as myVariableCount | eval myVariable=(if(myVariableCount&amp;gt;0,myVariableSum,0))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, &lt;CODE&gt;myVariable&lt;/CODE&gt; is guaranteed to be the sum, defaulted to 0 if otherwise null.&lt;/P&gt;

&lt;P&gt;How it works: This new sum relies on the fact that &lt;CODE&gt;count&lt;/CODE&gt; returns 0 in the event of a null input, unlike &lt;CODE&gt;sum(count)&lt;/CODE&gt; which returns null. So, we can check against the new variable that is guaranteed to be 0 instead of null. Only if the count is greater than 0 can the sum ever be, so we check the count, then use the sum conditionally.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Oct 2019 21:33:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355148#M105076</guid>
      <dc:creator>entpnerd</dc:creator>
      <dc:date>2019-10-31T21:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sum to have a value as zero in case not found</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355149#M105077</link>
      <description>&lt;P&gt;Add this to the end of your search &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search
| append 
    [ | makeresults 
    | eval FailedOccurences=0]
| stats max(FailedOccurences) as FailedOccurences
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope this helps&lt;/P&gt;

&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2019 01:16:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sum-to-have-a-value-as-zero-in-case-not-found/m-p/355149#M105077</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-11-01T01:16:48Z</dc:date>
    </item>
  </channel>
</rss>

