<?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: Unable to divide output of two queries in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Unable-to-divide-output-of-two-queries/m-p/510739#M142967</link>
    <description>&lt;P&gt;There are a couple of lapses in that query.&lt;/P&gt;&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;eval&lt;/FONT&gt; uses fields (&lt;FONT face="courier new,courier"&gt;max(total_atc_events)&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;max(atc_failures)&lt;/FONT&gt;)&amp;nbsp; that don't exist.&amp;nbsp; &lt;FONT face="courier new,courier"&gt;max&lt;/FONT&gt; is a &lt;FONT face="courier new,courier"&gt;stats&lt;/FONT&gt; function, not an &lt;FONT face="courier new,courier"&gt;eval&lt;/FONT&gt; function.&lt;/P&gt;&lt;P&gt;There seems to be some confusion over how append works.&amp;nbsp; I'll try to explain.&lt;/P&gt;&lt;P&gt;The main search returns a set of results with fields "count" and "total_atc_events".&lt;/P&gt;&lt;P&gt;The subsearch within append returns a separate set of results with fields "count" and "atc_failures".&lt;/P&gt;&lt;P&gt;It's like writing two shopping lists on the same page.&amp;nbsp; There's nothing to tie them together other than being on the same paper.&lt;/P&gt;&lt;P&gt;The solution is simple.&amp;nbsp; Use the stats command to correlate the two sets of results based on one or more common fields.&amp;nbsp; Do the events have a common field?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="wcnp_search-frontend" kubernetes.container_name=search-electrode-app "log.event"=ATC_CLICK 
| stats count by log.event |rename log.event as total_atc_events 
| append [ search index="wcnp_search-frontend" kubernetes.container_name=search-electrode-app "log.msg"="ATC click failure" | stats count by log.msg | rename log.msg as atc_failures ] 
| stats values(*) as * by &amp;lt;some common field name&amp;gt;
| eval error = max(total_atc_events) / max(atc_failures) 
| stats count by error&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 23 Jul 2020 21:09:37 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2020-07-23T21:09:37Z</dc:date>
    <item>
      <title>Unable to divide output of two queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Unable-to-divide-output-of-two-queries/m-p/510735#M142965</link>
      <description>&lt;P&gt;Hi team, I want to divide the output result of one query with output of second query and get a remainder. I am using the following query but unable to get any results for this&lt;BR /&gt;&lt;BR /&gt;index="wcnp_search-frontend" kubernetes.container_name=search-electrode-app "log.event"=ATC_CLICK | stats count by log.event |rename log.event as total_atc_events | append [ search index="wcnp_search-frontend" kubernetes.container_name=search-electrode-app "log.msg"="ATC click failure" | stats count by log.msg | rename log.msg as atc_failures ] | eval error = max(total_atc_events) / max(atc_failures) | stats count by error&lt;BR /&gt;Can anyone please assist ?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 20:17:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Unable-to-divide-output-of-two-queries/m-p/510735#M142965</guid>
      <dc:creator>preetham2215</dc:creator>
      <dc:date>2020-07-23T20:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to divide output of two queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Unable-to-divide-output-of-two-queries/m-p/510739#M142967</link>
      <description>&lt;P&gt;There are a couple of lapses in that query.&lt;/P&gt;&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;eval&lt;/FONT&gt; uses fields (&lt;FONT face="courier new,courier"&gt;max(total_atc_events)&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;max(atc_failures)&lt;/FONT&gt;)&amp;nbsp; that don't exist.&amp;nbsp; &lt;FONT face="courier new,courier"&gt;max&lt;/FONT&gt; is a &lt;FONT face="courier new,courier"&gt;stats&lt;/FONT&gt; function, not an &lt;FONT face="courier new,courier"&gt;eval&lt;/FONT&gt; function.&lt;/P&gt;&lt;P&gt;There seems to be some confusion over how append works.&amp;nbsp; I'll try to explain.&lt;/P&gt;&lt;P&gt;The main search returns a set of results with fields "count" and "total_atc_events".&lt;/P&gt;&lt;P&gt;The subsearch within append returns a separate set of results with fields "count" and "atc_failures".&lt;/P&gt;&lt;P&gt;It's like writing two shopping lists on the same page.&amp;nbsp; There's nothing to tie them together other than being on the same paper.&lt;/P&gt;&lt;P&gt;The solution is simple.&amp;nbsp; Use the stats command to correlate the two sets of results based on one or more common fields.&amp;nbsp; Do the events have a common field?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="wcnp_search-frontend" kubernetes.container_name=search-electrode-app "log.event"=ATC_CLICK 
| stats count by log.event |rename log.event as total_atc_events 
| append [ search index="wcnp_search-frontend" kubernetes.container_name=search-electrode-app "log.msg"="ATC click failure" | stats count by log.msg | rename log.msg as atc_failures ] 
| stats values(*) as * by &amp;lt;some common field name&amp;gt;
| eval error = max(total_atc_events) / max(atc_failures) 
| stats count by error&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 23 Jul 2020 21:09:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Unable-to-divide-output-of-two-queries/m-p/510739#M142967</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-07-23T21:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to divide output of two queries</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Unable-to-divide-output-of-two-queries/m-p/510756#M142993</link>
      <description>&lt;P&gt;index="wcnp_search-frontend" kubernetes.container_name=search-electrode-app "log.event"=ATC_CLICK&lt;BR /&gt;| stats count as total_atc_events by log.event&lt;BR /&gt;| appendcols&lt;BR /&gt;[ search index="wcnp_search-frontend" kubernetes.container_name=search-electrode-app "log.msg"="ATC click failure"&lt;BR /&gt;| stats count as atc_failures by log.msg ]&lt;BR /&gt;&lt;SPAN&gt;| eval error = max(total_atc_events) / max(atc_failures)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;if it's going to run&amp;nbsp;&lt;STRONG&gt;eval&lt;/STRONG&gt;, like above.&amp;nbsp;&lt;BR /&gt;I'm not sure what you want.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;index="wcnp_search-frontend" kubernetes.container_name=search-electrode-app "log.event"=ATC_CLICK OR "log.msg"="ATC click failure"&amp;nbsp;&lt;BR /&gt;| stats count(eval(log.event="ATC_CLICK")) as&amp;nbsp;&lt;SPAN&gt;total_atc_events count(eval(log.msg="ATC click failure")) as atc_faiures&lt;BR /&gt;| eval error = round(atc_failures / total_atc_events * 100,2)."%"&lt;BR /&gt;&lt;BR /&gt;Isn't that good enough?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 23:57:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Unable-to-divide-output-of-two-queries/m-p/510756#M142993</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-07-23T23:57:16Z</dc:date>
    </item>
  </channel>
</rss>

