<?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: Perform stats count based on the value of a field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333477#M99177</link>
    <description>&lt;P&gt;If you already have &lt;CODE&gt;action&lt;/CODE&gt; as a field with values that can be "success" or "failure" or something else (or nothing), what about:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... (action=success OR action=failure) 
| stats count by action, computer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;where &lt;CODE&gt;...&lt;/CODE&gt; is your original &lt;STRONG&gt;base&lt;/STRONG&gt; search. If you have already done some processing of the events, then you may have to resort to something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | search action=success OR action=failure
 | stats count by action, computer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;if&lt;/CODE&gt;'s in your search aren't complete and seem to be unneeded. &lt;/P&gt;</description>
    <pubDate>Wed, 13 Sep 2017 09:25:29 GMT</pubDate>
    <dc:creator>cpetterborg</dc:creator>
    <dc:date>2017-09-13T09:25:29Z</dc:date>
    <item>
      <title>Perform stats count based on the value of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333473#M99173</link>
      <description>&lt;P&gt;What I am looking to do is something of this nature:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count(eval(if(action=success))), count(eval(if(action=failure))) by computer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but it has not been working out as I had hoped. Can anyone fill me in on what I might be able to do in order to get this result in my stats area of my search?&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 04:41:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333473#M99173</guid>
      <dc:creator>JeffBothel</dc:creator>
      <dc:date>2017-09-13T04:41:08Z</dc:date>
    </item>
    <item>
      <title>Re: Perform stats count based on the value of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333474#M99174</link>
      <description>&lt;P&gt;Too much &lt;CODE&gt;if&lt;/CODE&gt;, not enough naming:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | stats count(eval(action=="success")) AS successes, count(eval(action=="failure")) AS failures BY computer
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Sep 2017 05:38:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333474#M99174</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-09-13T05:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Perform stats count based on the value of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333475#M99175</link>
      <description>&lt;P&gt;Making this correction to the query did not result in the desired outcome. The query returns 0 for each and every value that was specified when there are at least a few successes and failures in the queried items.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 06:12:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333475#M99175</guid>
      <dc:creator>JeffBothel</dc:creator>
      <dc:date>2017-09-13T06:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Perform stats count based on the value of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333476#M99176</link>
      <description>&lt;P&gt;I think your syntax is wrong. What about this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats 
    count(eval(if(action="success", 1, null()))) as success_count
    count(eval(if(action="failure", 1, null()))) as failure_count 
    by computer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or simply this instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats 
    count(eval(action="success")) as success_count
    count(eval(action="failure")) as failure_count 
    by computer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 07:32:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333476#M99176</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2017-09-13T07:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Perform stats count based on the value of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333477#M99177</link>
      <description>&lt;P&gt;If you already have &lt;CODE&gt;action&lt;/CODE&gt; as a field with values that can be "success" or "failure" or something else (or nothing), what about:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... (action=success OR action=failure) 
| stats count by action, computer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;where &lt;CODE&gt;...&lt;/CODE&gt; is your original &lt;STRONG&gt;base&lt;/STRONG&gt; search. If you have already done some processing of the events, then you may have to resort to something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | search action=success OR action=failure
 | stats count by action, computer
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The &lt;CODE&gt;if&lt;/CODE&gt;'s in your search aren't complete and seem to be unneeded. &lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 09:25:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333477#M99177</guid>
      <dc:creator>cpetterborg</dc:creator>
      <dc:date>2017-09-13T09:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: Perform stats count based on the value of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333478#M99178</link>
      <description>&lt;P&gt;Yes you are correct, the syntax is wrong but I was looking to get across what I am essentially trying to do in a clear and concise manner. I do know from having tried it previously that your second code idea does not work having put that into the search from a previous example of a similar type of code and that did not solve the issue. However, testing the first thought you had on the syntax generated the desired result for this case and as such thank you for your suggestion.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 09:32:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333478#M99178</guid>
      <dc:creator>JeffBothel</dc:creator>
      <dc:date>2017-09-13T09:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Perform stats count based on the value of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333479#M99179</link>
      <description>&lt;P&gt;This worked for me however success and failure need to be encapsulated in quotes - "success" &amp;amp; "failure"&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 14:16:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333479#M99179</guid>
      <dc:creator>tsullivan_pfpt</dc:creator>
      <dc:date>2018-02-09T14:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: Perform stats count based on the value of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333480#M99180</link>
      <description>&lt;P&gt;The count function using an eval seems to require an AS clause. As per the doco: "count(eval(status="404")) AS count_status" &lt;BR /&gt;
However count(eval(status="404")) without an as clause will cause a job inspector failure, and &lt;EM&gt;sometimes&lt;/EM&gt; you get a useful message: &lt;BR /&gt;
Error in 'stats' command: You must specify a rename for the aggregation specifier on the dynamically evaluated field 'count(eval(status="404"))'.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 13:39:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333480#M99180</guid>
      <dc:creator>drodman29</dc:creator>
      <dc:date>2018-07-11T13:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Perform stats count based on the value of a field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333481#M99181</link>
      <description>&lt;P&gt;I forgot the double-quotes.  It is fixed now.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jul 2018 15:35:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Perform-stats-count-based-on-the-value-of-a-field/m-p/333481#M99181</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-11T15:35:47Z</dc:date>
    </item>
  </channel>
</rss>

