<?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: How to treat nulls as zeros for purpose of adding? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41390#M9597</link>
    <description>&lt;P&gt;Coalesce is woefully underutilized and a great suggestion. However, as you have it here, it will produce a significantly different result than what the if(isnull()) commands I posted above will do, and significantly different than what atornes was looking for. Again though, props for remembering coalesce.&lt;/P&gt;

&lt;P&gt;If you really want to use coalesce in this situation you would need:&lt;/P&gt;

&lt;P&gt;| eval field1=coalesce(field1, 0) | eval field2=coalesce(field2, 0) |&lt;/P&gt;</description>
    <pubDate>Wed, 28 Dec 2011 18:18:30 GMT</pubDate>
    <dc:creator>rtadams89</dc:creator>
    <dc:date>2011-12-28T18:18:30Z</dc:date>
    <item>
      <title>How to treat nulls as zeros for purpose of adding?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41385#M9592</link>
      <description>&lt;P&gt;I'm trying to add 2 fields, each of which contains some nulls.  How can I treat these nulls as zeros for the purpose off adding?  When doing so as is, it the 2 values added together have returned null.&lt;/P&gt;

&lt;P&gt;There are no good examples of how to use the if() operator and the ifnull() operator has no documentation at all.  I'd imagine these are the best methods for achieving this.   Any help would be appreciated&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2011 15:56:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41385#M9592</guid>
      <dc:creator>atornes</dc:creator>
      <dc:date>2011-12-28T15:56:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to treat nulls as zeros for purpose of adding?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41386#M9593</link>
      <description>&lt;P&gt;Try this in the query --&amp;gt; fillnull value=0&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2011 17:24:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41386#M9593</guid>
      <dc:creator>Ravan</dc:creator>
      <dc:date>2011-12-28T17:24:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to treat nulls as zeros for purpose of adding?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41387#M9594</link>
      <description>&lt;P&gt;If you have two fields ("field1" and "field2"), you could put this in your search query before the addition is performed:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval field1=if(isnull(field1), 0, field1 | eval field2=if(isnull(field2), 0, field2) |
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There are slightly more compact ways to do the same thing, but the above should perform fine and will keep your search string easy to read.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2011 17:27:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41387#M9594</guid>
      <dc:creator>rtadams89</dc:creator>
      <dc:date>2011-12-28T17:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to treat nulls as zeros for purpose of adding?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41388#M9595</link>
      <description>&lt;P&gt;This is one of the more compact ways to do it. I would include the optional field parameters too, as you don't want to accidentaly set some fields equal to zero that should remain null. Also, it should default to "0", so the "value" parameter is optional.&lt;/P&gt;

&lt;P&gt;| fillnull field1 field2 |&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2011 17:32:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41388#M9595</guid>
      <dc:creator>rtadams89</dc:creator>
      <dc:date>2011-12-28T17:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to treat nulls as zeros for purpose of adding?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41389#M9596</link>
      <description>&lt;P&gt;The &lt;CODE&gt;eval&lt;/CODE&gt; command &lt;CODE&gt;coalesce&lt;/CODE&gt; is also useful for this purpose.  &lt;CODE&gt;coalesce&lt;/CODE&gt; will return the first non-null value from its set of arguments - using it is frequently easier than cascading &lt;CODE&gt;if&lt;/CODE&gt; statements.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval xyz=coalesce(field1,field2,field3,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Dec 2011 18:11:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41389#M9596</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2011-12-28T18:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to treat nulls as zeros for purpose of adding?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41390#M9597</link>
      <description>&lt;P&gt;Coalesce is woefully underutilized and a great suggestion. However, as you have it here, it will produce a significantly different result than what the if(isnull()) commands I posted above will do, and significantly different than what atornes was looking for. Again though, props for remembering coalesce.&lt;/P&gt;

&lt;P&gt;If you really want to use coalesce in this situation you would need:&lt;/P&gt;

&lt;P&gt;| eval field1=coalesce(field1, 0) | eval field2=coalesce(field2, 0) |&lt;/P&gt;</description>
      <pubDate>Wed, 28 Dec 2011 18:18:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-treat-nulls-as-zeros-for-purpose-of-adding/m-p/41390#M9597</guid>
      <dc:creator>rtadams89</dc:creator>
      <dc:date>2011-12-28T18:18:30Z</dc:date>
    </item>
  </channel>
</rss>

