<?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 perform calculations using eval command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-perform-calculations-using-eval-command/m-p/460905#M130020</link>
    <description>&lt;P&gt;At first, if you use both "stats count" and "stats avg" in the same search, the last expression is going to have no output, because of first one. Try to use eventstats instead.&lt;BR /&gt;
And at second thing: I'm not sure that "avg" function will work properly with your double quotes and percent mark(maybe Splunk understands "'4%'" expression as a String, not a number). But anyway, hope, it will help:&lt;BR /&gt;
   &lt;CODE&gt;| makeresults &lt;BR /&gt;
    | eval healthvalue="'4%'" &lt;BR /&gt;
    | eventstats count(eval(in(healthvalue, "'4%'","'5%'","'1%'","'8%'" ,"'12%'"))) as errorcount &lt;BR /&gt;
    | eventstats avg(eval(in(healthvalue, "'4%'","'5%'","'1%'","'8%'" ,"'12%'"))) as errorcount&lt;/CODE&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 12 Dec 2019 12:45:12 GMT</pubDate>
    <dc:creator>eduardKiyko</dc:creator>
    <dc:date>2019-12-12T12:45:12Z</dc:date>
    <item>
      <title>how to perform calculations using eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-perform-calculations-using-eval-command/m-p/460904#M130019</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
I have error_codes like 4%, 5%, 6% So I want to calculate them by performing&lt;BR /&gt;
| stats count(eval(in(healthvalue, "'4%'","'5%'","'1%'","'8%'" ,"'12%'"))) as errorcount &lt;BR /&gt;
| stats avg(eval(in(healthvalue, "'4%'","'5%'","'1%'","'8%'" ,"'12%'"))) as errorcount&lt;BR /&gt;
Any suggestions?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 12:19:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-perform-calculations-using-eval-command/m-p/460904#M130019</guid>
      <dc:creator>marisstella</dc:creator>
      <dc:date>2019-12-12T12:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to perform calculations using eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-perform-calculations-using-eval-command/m-p/460905#M130020</link>
      <description>&lt;P&gt;At first, if you use both "stats count" and "stats avg" in the same search, the last expression is going to have no output, because of first one. Try to use eventstats instead.&lt;BR /&gt;
And at second thing: I'm not sure that "avg" function will work properly with your double quotes and percent mark(maybe Splunk understands "'4%'" expression as a String, not a number). But anyway, hope, it will help:&lt;BR /&gt;
   &lt;CODE&gt;| makeresults &lt;BR /&gt;
    | eval healthvalue="'4%'" &lt;BR /&gt;
    | eventstats count(eval(in(healthvalue, "'4%'","'5%'","'1%'","'8%'" ,"'12%'"))) as errorcount &lt;BR /&gt;
    | eventstats avg(eval(in(healthvalue, "'4%'","'5%'","'1%'","'8%'" ,"'12%'"))) as errorcount&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 12:45:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-perform-calculations-using-eval-command/m-p/460905#M130020</guid>
      <dc:creator>eduardKiyko</dc:creator>
      <dc:date>2019-12-12T12:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to perform calculations using eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-perform-calculations-using-eval-command/m-p/460906#M130021</link>
      <description>&lt;P&gt;Thanks for your quick reply... it is not exactly looking only for the values mentioned.. it is looking for all the key values for the field healthvalue... I want to it to look for the values which I have specified only. any one of the other clauses will help like match, like, if or any?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 13:03:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-perform-calculations-using-eval-command/m-p/460906#M130021</guid>
      <dc:creator>marisstella</dc:creator>
      <dc:date>2019-12-12T13:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to perform calculations using eval command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-perform-calculations-using-eval-command/m-p/460907#M130022</link>
      <description>&lt;P&gt;Yes, any type of clause that works with eval according to documentation, will work, but in your case you can use "in" as well.&lt;BR /&gt;
For example, this search will show errorcount = 0(as there are no events with healthvalue 4%):&lt;BR /&gt;
&lt;CODE&gt;| makeresults &lt;BR /&gt;
| eval healthvalue="100%" &lt;BR /&gt;
| eventstats count(eval(in(healthvalue, "4%"))) as errorcount&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;And this one will show errorcount = 1(one event with healthvalue 4%):&lt;BR /&gt;
&lt;CODE&gt;| makeresults &lt;BR /&gt;
| eval healthvalue="4%" &lt;BR /&gt;
| eventstats count(eval(in(healthvalue, "4%"))) as errorcount&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Dec 2019 13:11:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-perform-calculations-using-eval-command/m-p/460907#M130022</guid>
      <dc:creator>eduardKiyko</dc:creator>
      <dc:date>2019-12-12T13:11:41Z</dc:date>
    </item>
  </channel>
</rss>

