<?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: Subsearch to store value in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/Subsearch-to-store-value/m-p/701078#M20418</link>
    <description>&lt;LI-CODE lang="markup"&gt;| stats count(eval(status="error")) AS FailCount count(eval(status="planning")) AS TotalPlanned
| eval percentageFailed=(FailCount/TotalPlanned)*10&lt;/LI-CODE&gt;</description>
    <pubDate>Sat, 05 Oct 2024 08:21:04 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2024-10-05T08:21:04Z</dc:date>
    <item>
      <title>Subsearch to store value</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Subsearch-to-store-value/m-p/701059#M20415</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am running two separate queries to extract values:&lt;/P&gt;&lt;P&gt;First query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc status=error | stats count AS FailCount&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc status=planning | stats count AS TotalPlanned&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both queries are working well and giving expected results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I combine them using sub search, I am getting error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc status=error
| stats count AS FailCount
[ search index=abc status=planning
| stats count AS TotalPlanned
| table TotalPlanned ]
| eval percentageFailed=(FailCount/TotalPlanned)*100 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error message:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Error in 'stats' command: The argument '(( TotalPlanned=761 )) is invalid'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: The count 761 is a valid count for TotalPlanned, so it did perform that calculation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2024 20:50:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Subsearch-to-store-value/m-p/701059#M20415</guid>
      <dc:creator>jam90</dc:creator>
      <dc:date>2024-10-04T20:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch to store value</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Subsearch-to-store-value/m-p/701071#M20417</link>
      <description>&lt;P&gt;It may help to think of a subsearch like a macro.&amp;nbsp; Just as the contents of a macro replace the macro name in a query, so, too, do the results of a subsearch replace the subsearch text in the query.&amp;nbsp; Therefore, it's important that the results of the subsearch make sense, semantically.&lt;/P&gt;&lt;P&gt;In the example query, once the subsearch completes, Splunk tries to execute this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc status=error
| stats count AS FailCount
(( TotalPlanned=761 ))
| eval percentageFailed=(FailCount/TotalPlanned)*100 &lt;/LI-CODE&gt;&lt;P&gt;which is not a valid query.&lt;/P&gt;&lt;P&gt;One fix is to use the &lt;FONT face="courier new,courier"&gt;appendcols&lt;/FONT&gt; command with the subsearch&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc status=error
| stats count AS FailCount
| appendcols [ search index=abc status=planning
  | stats count AS TotalPlanned
  | table TotalPlanned ]
| eval percentageFailed=(FailCount/TotalPlanned)*100 &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2024 00:16:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Subsearch-to-store-value/m-p/701071#M20417</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2024-10-05T00:16:35Z</dc:date>
    </item>
    <item>
      <title>Re: Subsearch to store value</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/Subsearch-to-store-value/m-p/701078#M20418</link>
      <description>&lt;LI-CODE lang="markup"&gt;| stats count(eval(status="error")) AS FailCount count(eval(status="planning")) AS TotalPlanned
| eval percentageFailed=(FailCount/TotalPlanned)*10&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 05 Oct 2024 08:21:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/Subsearch-to-store-value/m-p/701078#M20418</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2024-10-05T08:21:04Z</dc:date>
    </item>
  </channel>
</rss>

