<?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: Not seeing anything returned when using Sum with an eval IF statement in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711890#M240256</link>
    <description>&lt;P&gt;So sorry, I tested in a time frame with a Create event.&amp;nbsp; I thought it was working.&amp;nbsp; If I chose a time frame with no events, I still get an empty "Sum" field.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've removed the Double Qoutes: (| eval comparison=IF(isCreate&amp;gt;isClose,1, 0))&lt;/P&gt;&lt;P&gt;Also, changed the Stats count(Create) and count(Close) back to "sum".&amp;nbsp; I did this during testing, thanks for catching.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for the help.&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 17 Feb 2025 22:10:23 GMT</pubDate>
    <dc:creator>tdavison76</dc:creator>
    <dc:date>2025-02-17T22:10:23Z</dc:date>
    <item>
      <title>Not seeing anything returned when using Sum with an eval IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711884#M240251</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Thanks in advance for any help and Karma will be on the way :).&lt;/P&gt;&lt;P&gt;So I'm trying to create a Table that uses a "Sum" field that would show how many "Create" events exist that doesn't have a "Close" event.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'm doing this by using an eval IF statement&lt;/P&gt;&lt;P&gt;The issue I am having is when using "Sum", I get no results for Sum when there are not any events.&amp;nbsp; But, if I use "Count", I always get "1" returned.&lt;/P&gt;&lt;P&gt;Here's the Search I am using&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="healthcheck" integrationName="Opsgenie Edge Connector - Splunk", "alert.message"="[ThousandEyes] Alert for TMS Core Healthcheck", action IN ("Create","Close")
| eval Create=IF(action=="Create",1,0)
| eval Close=IF(action=="Close",1,0)
| stats count(Create) as isCreate, count(Close) as isClose by alert.id
| eval comparison=IF(isCreate&amp;gt;isClose,"1", "0")
| stats sum("comparison") as Sum count("comparison") as Count
| eval Application =  "TMS_API"
| eval test = Sum
| eval test1 = Count
| eval test2 = Application
| eval "Monitor Details" = "Performs a Health Check "
| table test, test1, test2 , "Monitor Details"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the returned results, I get an empty "test" field and a "1" in test1 field.&lt;/P&gt;&lt;P&gt;Thanks again for your help, and please let me know if more details are needed, this has been a huge headache for me.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 21:24:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711884#M240251</guid>
      <dc:creator>tdavison76</dc:creator>
      <dc:date>2025-02-17T21:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Not seeing anything returned when using Sum with an eval IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711885#M240252</link>
      <description>&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;The reason you're having an issue here is you're using "comparison" which is a string value - get rid of the double quotes and it will reference the field.&lt;/P&gt;&lt;P&gt;I've had a play using the below SPL to create some sample data and I think it now gives the result expected?&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
|  eval _raw = "[{\"integrationName\":\"Opsgenie Edge Connector - Splunk\",\"alert\":{\"message\":\"[ThousandEyes] Alert for TMS Core Healthcheck\",\"id\":\"abc123xyz\"},\"action\":\"Create\"},{\"integrationName\":\"Opsgenie Edge Connector - Splunk\",\"alert\":{\"message\":\"[ThousandEyes] Alert for TMS Core Healthcheck\",\"id\":\"abc123xyz\"},\"action\":\"Close\"},{\"integrationName\":\"Opsgenie Edge Connector - Splunk\",\"alert\":{\"message\":\"[ThousandEyes] Alert for TMS Core Healthcheck\",\"id\":\"def456uvw\"},\"action\":\"Create\"},{\"integrationName\":\"Opsgenie Edge Connector - Splunk\",\"alert\":{\"message\":\"[ThousandEyes] Alert for TMS Core Healthcheck\",\"id\":\"def456uvw\"},\"action\":\"Close\"},{\"integrationName\":\"Opsgenie Edge Connector - Splunk\",\"alert\":{\"message\":\"[ThousandEyes] Alert for TMS Core Healthcheck\",\"id\":\"ghi789rst\"},\"action\":\"Create\"}]"
| eval events=json_array_to_mv(_raw)
| mvexpand events
| eval _raw=events
| fields _raw
| spath
``` Prep work complete ```
| eval Create=IF(action=="Create",1,0)
| eval Close=IF(action=="Close",1,0)
| stats sum(Create) as isCreate, sum(Close) as isClose by alert.id
| eval comparison=IF(isCreate&amp;gt;isClose,"1", "0")
| stats sum(comparison) as Sum count(comparison) as Count
| eval Application =  "TMS_API"
| eval test = Sum
| eval test1 = Count
| eval test2 = Application
| eval "Monitor Details" = "Performs a Health Check "
| table test, test1, test2 , "Monitor Details"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know how you get on and consider accepting this answer or adding karma this answer if it has helped.&lt;BR /&gt;Regards&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 21:38:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711885#M240252</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-02-17T21:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Not seeing anything returned when using Sum with an eval IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711886#M240253</link>
      <description>&lt;P&gt;I also noticed another issue, you're using "count" instead of "sum" for:&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats count(Create) as isCreate, count(Close) as isClose by alert.id&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Should be&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats sum(Create) as isCreate, sum(Close) as isClose by alert.id&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;(I might have given you this SPL previously?? If so apologies!&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 21:39:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711886#M240253</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-02-17T21:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Not seeing anything returned when using Sum with an eval IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711889#M240255</link>
      <description>&lt;P&gt;You came thru again,&amp;nbsp; twice in one day!!.&amp;nbsp; &amp;nbsp;Simply awesome, thank you for your help on all of this.&amp;nbsp; It's working like a charm now.&lt;/P&gt;&lt;P&gt;Have a good week.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 21:54:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711889#M240255</guid>
      <dc:creator>tdavison76</dc:creator>
      <dc:date>2025-02-17T21:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: Not seeing anything returned when using Sum with an eval IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711890#M240256</link>
      <description>&lt;P&gt;So sorry, I tested in a time frame with a Create event.&amp;nbsp; I thought it was working.&amp;nbsp; If I chose a time frame with no events, I still get an empty "Sum" field.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've removed the Double Qoutes: (| eval comparison=IF(isCreate&amp;gt;isClose,1, 0))&lt;/P&gt;&lt;P&gt;Also, changed the Stats count(Create) and count(Close) back to "sum".&amp;nbsp; I did this during testing, thanks for catching.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for the help.&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 22:10:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711890#M240256</guid>
      <dc:creator>tdavison76</dc:creator>
      <dc:date>2025-02-17T22:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Not seeing anything returned when using Sum with an eval IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711891#M240257</link>
      <description>&lt;P&gt;I think this is because when no data is returned, you're trying to take a sum of no fields which is Null, however the count value is 0, if that makes sense?&lt;/P&gt;&lt;P&gt;You could probably fix this with:&lt;BR /&gt;| eval test = COALESCE(Sum,0)&lt;BR /&gt;instead of&lt;BR /&gt;| eval test = Sum&lt;BR /&gt;&lt;BR /&gt;Which will mean that if Sum is Null it will use the value 0.&amp;nbsp;&lt;BR /&gt;Would this work for you?&lt;/P&gt;&lt;P&gt;Will&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2025 22:14:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711891#M240257</guid>
      <dc:creator>livehybrid</dc:creator>
      <dc:date>2025-02-17T22:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Not seeing anything returned when using Sum with an eval IF statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711917#M240261</link>
      <description>&lt;P&gt;The COALESCE did the trick.&amp;nbsp; You are awesome.&amp;nbsp; Thanks for all of the help.&amp;nbsp; I can finally get a good nights rest. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Tue, 18 Feb 2025 13:37:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Not-seeing-anything-returned-when-using-Sum-with-an-eval-IF/m-p/711917#M240261</guid>
      <dc:creator>tdavison76</dc:creator>
      <dc:date>2025-02-18T13:37:06Z</dc:date>
    </item>
  </channel>
</rss>

