<?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: Splunk Using Result from Subsearch in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127421#M34566</link>
    <description>&lt;P&gt;Thanks i did something similar, it worked!!&lt;/P&gt;

&lt;P&gt;Btw, for different ppurposes, cant i use the subsearch in my original way to calculate something and return a value for the outer query?&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jul 2015 00:29:29 GMT</pubDate>
    <dc:creator>ehaque</dc:creator>
    <dc:date>2015-07-17T00:29:29Z</dc:date>
    <item>
      <title>Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127416#M34561</link>
      <description>&lt;P&gt;Hi, i need to do following from table x for field a and b&lt;/P&gt;

&lt;P&gt;For each category b&lt;BR /&gt;
 - sum(a) / (total rows from table x) &lt;/P&gt;

&lt;P&gt;I am using subsearch to calc (total rows from x)  as shown below. Is there better way. I am getting&lt;BR /&gt;
"Error in 'SearchProcessor': Mismatched quotes and/or parenthesis."&lt;/P&gt;

&lt;H2&gt;SPL CODE&lt;/H2&gt;

&lt;P&gt;source="vx-fcr.csv" host="vx-contacts" sourcetype="csv-vx-fcr" date_year = 2015 earliest=-60d&lt;BR /&gt;
| timechart span=1w &lt;BR /&gt;
eval(&lt;BR /&gt;
sum(a)&lt;BR /&gt;
/ &lt;BR /&gt;
tonumber([search source="vx-fcr.csv" host="vx-contacts" sourcetype="csv-vx-fcr" date_year = 2015 earliest=-60d | stats sum(count_fcr_eligible_cases) as total | return $total])&lt;BR /&gt;
)   by b&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 06:43:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127416#M34561</guid>
      <dc:creator>ehaque</dc:creator>
      <dc:date>2020-09-29T06:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127417#M34562</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="vx-fcr.csv" host="vx-contacts" sourcetype="csv-vx-fcr" date_year = 2015 earliest=-60d | eventstats sum(count_fcr_eligible_cases) as total | timechart span=1w eval(sum(a)/total) BY b
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jul 2015 23:20:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127417#M34562</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-07-16T23:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127418#M34563</link>
      <description>&lt;P&gt;This will result in an error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'timechart' command: Only the split-by and x-axis fields can be directly referenced in the eval expression.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I know, because I tried it myself this way &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Jul 2015 23:29:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127418#M34563</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2015-07-16T23:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127419#M34564</link>
      <description>&lt;P&gt;No need for a subsearch, which is quite inefficient. The date_year field is unnecessary. Another thing - the timechart command requires a statistical function as an argument;  notice that I have used "avg(calcA)". Here is a link to &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.4/SearchReference/CommonStatsFunctions"&gt;the statistical functions&lt;/A&gt; that timechart supports:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="vx-fcr.csv" host="vx-contacts" sourcetype="csv-vx-fcr" earliest=-60d
|stats sum(a) as sum_a count by b
| eventstats sum(count) as total
| eval calcA = sum_a / total
| timechart span=1w avg(calcA)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jul 2015 23:30:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127419#M34564</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-07-16T23:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127420#M34565</link>
      <description>&lt;P&gt;OK, like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="vx-fcr.csv" host="vx-contacts" sourcetype="csv-vx-fcr" date_year = 2015 earliest=-60d | eventstats sum(count_fcr_eligible_cases) as total | timechart span=1w sum(a) AS sumA BY b | eval sumA=sumA/total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Jul 2015 23:54:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127420#M34565</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-07-16T23:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127421#M34566</link>
      <description>&lt;P&gt;Thanks i did something similar, it worked!!&lt;/P&gt;

&lt;P&gt;Btw, for different ppurposes, cant i use the subsearch in my original way to calculate something and return a value for the outer query?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2015 00:29:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127421#M34566</guid>
      <dc:creator>ehaque</dc:creator>
      <dc:date>2015-07-17T00:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127422#M34567</link>
      <description>&lt;P&gt;Thanks all!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2015 00:30:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127422#M34567</guid>
      <dc:creator>ehaque</dc:creator>
      <dc:date>2015-07-17T00:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127423#M34568</link>
      <description>&lt;P&gt;Sometimes subsearch is the only way to solve a problem, but it is usually not the most efficient way. Also, subsearches have limitations that a base search does not. The "Splunk" way to do it is to collect &lt;EM&gt;all&lt;/EM&gt; the data in the base search, if possible.&lt;/P&gt;

&lt;P&gt;Often, using subsearches and where commands reflects an SQL mode of thinking, which usually leads to less effective solutions. And you can't use subsearches everywhere... for example, you can't insert the results of a subsearch into a timechart command!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2015 08:40:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127423#M34568</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-07-17T08:40:34Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127424#M34569</link>
      <description>&lt;P&gt;Hey Woodcock,&lt;/P&gt;

&lt;P&gt;I'm using a similar syntax and noticed that this: &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;"timechart span=1w sum(a) AS sumA BY b | eval sumA=sumA/total"&lt;/STRONG&gt;&lt;BR /&gt;
works and this:&lt;BR /&gt;
&lt;STRONG&gt;"timechart span=1w sum(a) AS sumA  | eval sumA=sumA/total"&lt;/STRONG&gt;&lt;BR /&gt;
does not. &lt;/P&gt;

&lt;P&gt;Is there any specific reason that this is the case? Hard coding a number in place of total works in all cases.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 21:17:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127424#M34569</guid>
      <dc:creator>ConnorG</dc:creator>
      <dc:date>2015-08-13T21:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Using Result from Subsearch</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127425#M34570</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="vx-fcr.csv" host="vx-contacts" sourcetype="csv-vx-fcr" date_year = 2015 earliest=-60d | eventstats sum(count_fcr_eligible_cases) as total | timechart span=1w first(total) AS total sum(a) AS sumA BY b | eval sumA=sumA/total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="vx-fcr.csv" host="vx-contacts" sourcetype="csv-vx-fcr" date_year = 2015 earliest=-60d | eventstats sum(count_fcr_eligible_cases) as total | timechart span=1w first(total) AS total sum(a) AS sumA | eval sumA=sumA/total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Don't forget to click "Accept" to close out the Question if it works.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Aug 2015 22:29:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Using-Result-from-Subsearch/m-p/127425#M34570</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-08-13T22:29:45Z</dc:date>
    </item>
  </channel>
</rss>

