<?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: How do I count the number of events based on the value of a field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224526#M66141</link>
    <description>&lt;P&gt;You can use the Splunk top command.   It will automatically give you a percentage as well and i've turned that off in the search below. &lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/Top"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/Top&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;index = "SAMPLE INDEX"  | top showperc=false "NEW STATE" &lt;/P&gt;</description>
    <pubDate>Wed, 09 Nov 2016 19:07:23 GMT</pubDate>
    <dc:creator>sdaniels</dc:creator>
    <dc:date>2016-11-09T19:07:23Z</dc:date>
    <item>
      <title>How do I count the number of events based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224525#M66140</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I am having trouble with a simple search.  I have the following data:&lt;/P&gt;

&lt;P&gt;OBJECT ID,NEW STATE&lt;BR /&gt;
1,STATE ONE&lt;BR /&gt;
1,STATE TWO&lt;BR /&gt;
1,STATE THREE&lt;BR /&gt;
2,STATE ONE&lt;BR /&gt;
2,STATE TWO&lt;BR /&gt;
2,STATE ONE&lt;BR /&gt;
3,STATE ONE&lt;/P&gt;

&lt;P&gt;...and so forth&lt;/P&gt;

&lt;P&gt;I would like to return the number of events in which "NEW STATE" = "STATE ONE".  I have the following search:&lt;/P&gt;

&lt;P&gt;index = "SAMPLE INDEX" | stats count(eval("NEW STATE" = "STATE ONE")) as "COUNT"&lt;/P&gt;

&lt;P&gt;Instead of returning "COUNT"=4, it returns 0 and I can't understand why.  Is there something missing?&lt;/P&gt;

&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;

&lt;P&gt;Thank you,&lt;/P&gt;

&lt;P&gt;Andrew&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2016 15:34:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224525#M66140</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2016-11-09T15:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of events based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224526#M66141</link>
      <description>&lt;P&gt;You can use the Splunk top command.   It will automatically give you a percentage as well and i've turned that off in the search below. &lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/Top"&gt;http://docs.splunk.com/Documentation/Splunk/6.5.0/SearchReference/Top&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;index = "SAMPLE INDEX"  | top showperc=false "NEW STATE" &lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2016 19:07:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224526#M66141</guid>
      <dc:creator>sdaniels</dc:creator>
      <dc:date>2016-11-09T19:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of events based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224527#M66142</link>
      <description>&lt;P&gt;First off:  you should consider changing your data definition to not include spaces in field names.  I am not very experienced, but spaces in field names have already caused problems.  Try denoting words by using CamelCase or separating them with underscores "_"&lt;/P&gt;

&lt;P&gt;As to your question, if you are really only interested in a single state, you can filter your results before getting a count&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;index = "SAMPLE INDEX" | search "STATE ONE" | stats count&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;If you are trying to get counts for everything, you can just count by the field&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;index = "SAMPLE INDEX" | stats count by "NEW STATE"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;But it is possible that Splunk will misinterpret the field "NEW STATE" because of the space in it, so it may just be found as "STATE".  So if the above doesn't work, try this:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;index = "SAMPLE INDEX" | stats count by "STATE"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Wed, 09 Nov 2016 20:32:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224527#M66142</guid>
      <dc:creator>MonkeyK</dc:creator>
      <dc:date>2016-11-09T20:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of events based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224528#M66143</link>
      <description>&lt;P&gt;As a optimized search you should include filter upfront rather than later. Following should work with better performance:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index = "SAMPLE INDEX" "NEW STATE"="STATE ONE"| stats count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you intend to use your own query replace double quotes with single quotes for the &lt;STRONG&gt;'New State'&lt;/STRONG&gt; field. As within eval expression it does not match the field but value on both left and right hand side.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index = "SAMPLE INDEX" | stats count(eval('NEW STATE' = "STATE ONE")) as "COUNT"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Nov 2016 21:59:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224528#M66143</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2016-11-09T21:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I count the number of events based on the value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224529#M66144</link>
      <description>&lt;P&gt;Thanks for the suggestion and the solution to my problem!&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2016 09:55:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-count-the-number-of-events-based-on-the-value-of-a/m-p/224529#M66144</guid>
      <dc:creator>andrewtrobec</dc:creator>
      <dc:date>2016-11-11T09:55:26Z</dc:date>
    </item>
  </channel>
</rss>

