<?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: Using eval with subsearch stats as an argument in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-eval-with-subsearch-stats-as-an-argument/m-p/62002#M15309</link>
    <description>&lt;P&gt;You can use &lt;CODE&gt;return&lt;/CODE&gt; like this, too:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; source="app" | stats dc(user_id) as users | eval percent=[search source="app" log_info=* | stats dc(user_id) as errs | return $errs]/users
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 17 Aug 2015 22:01:31 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-08-17T22:01:31Z</dc:date>
    <item>
      <title>Using eval with subsearch stats as an argument</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-eval-with-subsearch-stats-as-an-argument/m-p/61999#M15306</link>
      <description>&lt;P&gt;Hullo,&lt;/P&gt;

&lt;P&gt;I have a set of messages as data which are various events being sent from an app.  Every single message has the user_id field, and some of them have a log_info field, which indicates that the message was sent to indicate an error.  I want to find out what percentage of users are encountering errors over the past X minutes.&lt;/P&gt;

&lt;P&gt;Here's what I have so far.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="app" | stats dc(user_id) as users | eval percent=[search source="app" log_info=* | stats dc(user_id)]/users
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I retrieve all the messages from the app initially, and then store a distinct count as 'users'.  I run an eval to divide my subsearch by users.  My subsearch does the same thing as the initial search, except further narrows down to only the messages with errors.&lt;/P&gt;

&lt;P&gt;I've checked and both the searches work.  In addition, if I run something like eval percent=users*50 it works fine, so I know that the datatype returned by stats dc() can be plugged into eval.  Not sure what I could be doing wrong.&lt;/P&gt;

&lt;P&gt;Thanks for any help!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:04:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-eval-with-subsearch-stats-as-an-argument/m-p/61999#M15306</guid>
      <dc:creator>erikross</dc:creator>
      <dc:date>2020-09-28T14:04:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using eval with subsearch stats as an argument</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-eval-with-subsearch-stats-as-an-argument/m-p/62000#M15307</link>
      <description>&lt;P&gt;Figures that after a couple hours of trying, I'd figure it out 30 minutes after posting.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="app" | stats dc(user_id) as users | eval percent=[search source="app" log_info=* | stats dc(user_id) as errs | rename errs as query]/users
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works.  Next up is finding out how to make it play nice with timechart instead of stats.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2013 23:01:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-eval-with-subsearch-stats-as-an-argument/m-p/62000#M15307</guid>
      <dc:creator>erikross</dc:creator>
      <dc:date>2013-06-12T23:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using eval with subsearch stats as an argument</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-eval-with-subsearch-stats-as-an-argument/m-p/62001#M15308</link>
      <description>&lt;P&gt;Thanks!&lt;BR /&gt;
Have been looking for this for days..&lt;BR /&gt;
("query" as a column name for returning values to eval expressions..)&lt;/P&gt;

&lt;P&gt;Is that anywhere in the documentation?&lt;/P&gt;</description>
      <pubDate>Sat, 14 Mar 2015 16:37:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-eval-with-subsearch-stats-as-an-argument/m-p/62001#M15308</guid>
      <dc:creator>ionis</dc:creator>
      <dc:date>2015-03-14T16:37:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using eval with subsearch stats as an argument</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-eval-with-subsearch-stats-as-an-argument/m-p/62002#M15309</link>
      <description>&lt;P&gt;You can use &lt;CODE&gt;return&lt;/CODE&gt; like this, too:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; source="app" | stats dc(user_id) as users | eval percent=[search source="app" log_info=* | stats dc(user_id) as errs | return $errs]/users
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Aug 2015 22:01:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-eval-with-subsearch-stats-as-an-argument/m-p/62002#M15309</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-17T22:01:31Z</dc:date>
    </item>
  </channel>
</rss>

