<?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: STATS COUNT on same field before and after WHERE / Condition? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/STATS-COUNT-on-same-field-before-and-after-WHERE-Condition/m-p/388646#M173014</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... 
| xmlkv 
| table _time, qName, pendingMsgs 
| eval hasPending = (pendingMsgs &amp;gt; 0,1,0)
| stats count(qName) as totalQueues sum(hasPending) as queuesWithPendingMessages
| eval percentage = (queuesWithPendingMessages / totalQueues) * 100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope it helps!&lt;/P&gt;</description>
    <pubDate>Thu, 14 Feb 2019 19:24:01 GMT</pubDate>
    <dc:creator>chrisyounger</dc:creator>
    <dc:date>2019-02-14T19:24:01Z</dc:date>
    <item>
      <title>STATS COUNT on same field before and after WHERE / Condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/STATS-COUNT-on-same-field-before-and-after-WHERE-Condition/m-p/388645#M173013</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;

&lt;P&gt;What I want is :&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;&lt;P&gt;Total no. of queues and total no. of queues with pending messages.&lt;BR /&gt;
Something like this :&lt;/P&gt;

&lt;P&gt;.... | xmlkv | table _time, qName, pendingMsgs | stats count(qName) as totalQueues | stats count(qName) where  pendingMsgs &amp;gt; 0 as queuesWithPendingMessages&lt;BR /&gt;
&lt;STRONG&gt;I want to achieve the working of last pipe and also save the values to calculate the percentage.&lt;/STRONG&gt;&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Or Output to be like this :&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;totalQueues&lt;/STRONG&gt;  = &lt;STRONG&gt;&lt;EM&gt;15&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;queuesWithPendingMessages&lt;/STRONG&gt;  = &lt;STRONG&gt;&lt;EM&gt;4&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;Percentage&lt;/STRONG&gt; (queuesWithPendingMessages / totalQueues) x 100  = &lt;STRONG&gt;&lt;EM&gt;26.66&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Please help.&lt;/P&gt;

&lt;P&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 19:15:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/STATS-COUNT-on-same-field-before-and-after-WHERE-Condition/m-p/388645#M173013</guid>
      <dc:creator>vaibhavvijay9</dc:creator>
      <dc:date>2019-02-14T19:15:47Z</dc:date>
    </item>
    <item>
      <title>Re: STATS COUNT on same field before and after WHERE / Condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/STATS-COUNT-on-same-field-before-and-after-WHERE-Condition/m-p/388646#M173014</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... 
| xmlkv 
| table _time, qName, pendingMsgs 
| eval hasPending = (pendingMsgs &amp;gt; 0,1,0)
| stats count(qName) as totalQueues sum(hasPending) as queuesWithPendingMessages
| eval percentage = (queuesWithPendingMessages / totalQueues) * 100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope it helps!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 19:24:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/STATS-COUNT-on-same-field-before-and-after-WHERE-Condition/m-p/388646#M173014</guid>
      <dc:creator>chrisyounger</dc:creator>
      <dc:date>2019-02-14T19:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: STATS COUNT on same field before and after WHERE / Condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/STATS-COUNT-on-same-field-before-and-after-WHERE-Condition/m-p/388647#M173015</link>
      <description>&lt;P&gt;Got it!&lt;BR /&gt;
Here is the solution :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... | xmlkv | table _time, qName, pendingMsgs | stats count(qName) as totalQueues, count(eval(pendingMsgs &amp;gt; 0)) as queuesWithPendingMessages | eval percentage=(queuesWithPendingMessages/totalQueues)*100
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;But is it fully (logically) correct? Please share your views.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Awaiting your response. &lt;BR /&gt;
Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 19:26:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/STATS-COUNT-on-same-field-before-and-after-WHERE-Condition/m-p/388647#M173015</guid>
      <dc:creator>vaibhavvijay9</dc:creator>
      <dc:date>2019-02-14T19:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: STATS COUNT on same field before and after WHERE / Condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/STATS-COUNT-on-same-field-before-and-after-WHERE-Condition/m-p/388648#M173016</link>
      <description>&lt;P&gt;Hi @chrisyoungerjds,&lt;/P&gt;

&lt;P&gt;Thanks a lot for the quick response! &lt;/P&gt;

&lt;P&gt;Your provided string is displaying error as :&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Error in 'eval' command: The expression is malformed. Expected ).&lt;/STRONG&gt; &lt;/P&gt;

&lt;P&gt;&lt;EM&gt;However, I have got the solution while trying it by myself, and I have posted it here as answer.&lt;/EM&gt; &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;But is it fully (logically) correct? Please share your views.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Awaiting your response. &lt;BR /&gt;
Thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 19:38:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/STATS-COUNT-on-same-field-before-and-after-WHERE-Condition/m-p/388648#M173016</guid>
      <dc:creator>vaibhavvijay9</dc:creator>
      <dc:date>2019-02-14T19:38:56Z</dc:date>
    </item>
  </channel>
</rss>

