<?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: chart sum eval if  not working.... in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/chart-sum-eval-if-not-working/m-p/75121#M18968</link>
    <description>&lt;P&gt;I am not sure "if" works with "chart" but it does with "stats" :&lt;BR /&gt;
| stats sum(eval(if(eventtype=="SOME_EVENT,SOME_FIELD",0))) as SOME_TOTAL&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 11:25:35 GMT</pubDate>
    <dc:creator>MarioM</dc:creator>
    <dc:date>2020-09-28T11:25:35Z</dc:date>
    <item>
      <title>chart sum eval if  not working....</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sum-eval-if-not-working/m-p/75120#M18967</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have the following search string which works&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(sourcetype="cds_fms_access" x_event="*connect" x_status="200") | chart sum(bytes) as sum by hostname, x_event 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And will give a results like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;hostname       connect        disconnect
--------       -------        ----------
host1           1000          2000
host2           500           1500
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to add one more field to chart eventype. something like this, which wont work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  (sourcetype="cds_fms_access" x_event="*connect" x_status="200") | chart sum(bytes) as sum by hostname, x_event , eventtype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I am trying to do is calculate the bytes if x_event=connect and disconnect separately by hostname and eventtype. &lt;/P&gt;

&lt;P&gt;I have tried to use &lt;CODE&gt;sum(eval(if(x_event="disconnect",0)))&lt;/CODE&gt; but i have got an error &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;""Error in 'chart' command: The eval expression for dynamic field 'if(x_event="disconnect",0)' is invalid. Error='The arguments to the 'if' function are invalid.'"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please Help.&lt;/P&gt;

&lt;P&gt;Thanks in Advance &lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2012 01:48:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sum-eval-if-not-working/m-p/75120#M18967</guid>
      <dc:creator>KarunK</dc:creator>
      <dc:date>2012-02-21T01:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: chart sum eval if  not working....</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sum-eval-if-not-working/m-p/75121#M18968</link>
      <description>&lt;P&gt;I am not sure "if" works with "chart" but it does with "stats" :&lt;BR /&gt;
| stats sum(eval(if(eventtype=="SOME_EVENT,SOME_FIELD",0))) as SOME_TOTAL&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 11:25:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sum-eval-if-not-working/m-p/75121#M18968</guid>
      <dc:creator>MarioM</dc:creator>
      <dc:date>2020-09-28T11:25:35Z</dc:date>
    </item>
    <item>
      <title>Re: chart sum eval if  not working....</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sum-eval-if-not-working/m-p/75122#M18969</link>
      <description>&lt;P&gt;As per the docs;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/CommonEvalFunctions"&gt;http://docs.splunk.com/Documentation/Splunk/4.3/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;The IF statement requires three inputs, the test, IF true and a final value for IF not true (the else)&lt;/P&gt;

&lt;P&gt;An example from the docs for quick reference;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;err=if(error == 200, "OK", "Error")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Feb 2012 11:35:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sum-eval-if-not-working/m-p/75122#M18969</guid>
      <dc:creator>Drainy</dc:creator>
      <dc:date>2012-02-21T11:35:12Z</dc:date>
    </item>
  </channel>
</rss>

