<?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 to get count of events for each field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285216#M176722</link>
    <description>&lt;P&gt;Well, the aggregation done on eventstats and the stats just before that is same, so they're kind of redundant. I would just use like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo=* bar=* | stats count as AmountByClient  by bar foo | stats sum(AmountByClient) AS "Total Count" list(bar) as Clients list(AmountByClient) as "Client Count" by foo
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 16 Sep 2016 14:52:31 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-09-16T14:52:31Z</dc:date>
    <item>
      <title>How to get count of events for each field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285211#M176717</link>
      <description>&lt;P&gt;In the following query, I'm trying to display the count of events for each field (bar) from a single field (foo).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo=* bar=* | stats values(bar) as Clients count as Amount by foo | eventstats sum(Amount) as AmountByClient by foo | stats sum(Amount) AS "Total Count", list(foo) as Clients list(AmountByClient) as "Client Count" by bar
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;On each foo field, I can get all the bars and stat the total amount of events for that group of bars, but I will like to get the count for each bar individually.&lt;/P&gt;

&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 15:15:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285211#M176717</guid>
      <dc:creator>Yaichael</dc:creator>
      <dc:date>2016-09-15T15:15:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of events for each field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285212#M176718</link>
      <description>&lt;P&gt;How a bout this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo=* bar=* | stats count as Amount by foo bar |  eventstats sum(Amount) as AmountByClient by foo | stats sum(Amount) AS "Total Count", list(foo) as Clients list(AmountByClient) as "Client Count" by bar
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2016 15:42:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285212#M176718</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-15T15:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of events for each field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285213#M176719</link>
      <description>&lt;P&gt;Thanks for the reply, someoni2.&lt;/P&gt;

&lt;P&gt;Using your answer as reference, I reconfigured my query as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo=* bar=* | stats count as Amount by bar foo | eventstats sum(Amount) as AmountByClient by foo | stats sum(Amount) AS "Total Count" list(bar) as Clients list(AmountByClient) as "Client Count" by foo
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but each "Client Count" is being reflected as "Total Count". I played around with it, but I'm still getting unwanted results.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 18:57:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285213#M176719</guid>
      <dc:creator>Yaichael</dc:creator>
      <dc:date>2016-09-15T18:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of events for each field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285214#M176720</link>
      <description>&lt;P&gt;In my query, I'm using bar in the last stats, whereas you're using foo. Try with bar. Or if you want to group by foo in the last, then try like this (swapping bar with foo)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo=* bar=* | stats count as Amount by foo bar |  eventstats sum(Amount) as AmountByClient by bar | stats sum(Amount) AS "Total Count", list(bar) as Clients list(AmountByClient) as "Client Count" by foo
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2016 19:45:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285214#M176720</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-15T19:45:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of events for each field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285215#M176721</link>
      <description>&lt;P&gt;Found the error! I was missing foo in the eventstats command.&lt;/P&gt;

&lt;P&gt;Thanks for the help!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo=* bar=* | stats count as Amount by bar foo | eventstats sum(Amount) as AmountByClient by bar foo | stats sum(Amount) AS "Total Count" list(bar) as Clients list(AmountByClient) as "Client Count" by foo
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Sep 2016 13:13:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285215#M176721</guid>
      <dc:creator>Yaichael</dc:creator>
      <dc:date>2016-09-16T13:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of events for each field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285216#M176722</link>
      <description>&lt;P&gt;Well, the aggregation done on eventstats and the stats just before that is same, so they're kind of redundant. I would just use like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;foo=* bar=* | stats count as AmountByClient  by bar foo | stats sum(AmountByClient) AS "Total Count" list(bar) as Clients list(AmountByClient) as "Client Count" by foo
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Sep 2016 14:52:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285216#M176722</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-09-16T14:52:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get count of events for each field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285217#M176723</link>
      <description>&lt;P&gt;Yeah, you're right.&lt;/P&gt;

&lt;P&gt;Thanks for the suggestion!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2016 15:46:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-count-of-events-for-each-field/m-p/285217#M176723</guid>
      <dc:creator>Yaichael</dc:creator>
      <dc:date>2016-09-16T15:46:24Z</dc:date>
    </item>
  </channel>
</rss>

