<?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 group and add the count for each value of a field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-and-add-the-count-for-each-value-of-a-field/m-p/220724#M64847</link>
    <description>&lt;P&gt;Hello @emamedov,&lt;BR /&gt;
I ran into a similar problem and found a solution hidden in the splunk archives here. For your use case, try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; eventtype=product-view 
 | stats count by username, productname
 | stats list(username) as "User Name" list(count) as count by productname
 | rename productname as "Product Name"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Good luck and happy hunting!&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jan 2016 17:52:25 GMT</pubDate>
    <dc:creator>dark_15</dc:creator>
    <dc:date>2016-01-12T17:52:25Z</dc:date>
    <item>
      <title>How to group and add the count for each value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-and-add-the-count-for-each-value-of-a-field/m-p/220721#M64844</link>
      <description>&lt;P&gt;I am currently trying to group together unique products, and have the username listed under each product, however, I want to also add a count and that is where I hit a roadblock. I have looked at multiple posts regarding this topic and can't quite get over the finish line.&lt;/P&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;P&gt;Instead of:&lt;BR /&gt;
Product A:&lt;BR /&gt;
User1&lt;BR /&gt;
User2&lt;BR /&gt;
User2&lt;BR /&gt;
User2&lt;BR /&gt;
User3&lt;/P&gt;

&lt;P&gt;Product B:&lt;BR /&gt;
User 1&lt;BR /&gt;
User 1&lt;BR /&gt;
User 2&lt;/P&gt;

&lt;P&gt;I would like to have:&lt;/P&gt;

&lt;P&gt;Product A:&lt;BR /&gt;
User 1 - 1&lt;BR /&gt;
User 2 - 3&lt;BR /&gt;
User 3 - 1&lt;/P&gt;

&lt;P&gt;Product B:&lt;BR /&gt;
User 1 - 2&lt;BR /&gt;
User 2 - 1&lt;/P&gt;

&lt;P&gt;Below is the search string I'm currently using to generate just the grouped product/users:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=product-view|stats values(username) by productname
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jan 2016 21:56:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-and-add-the-count-for-each-value-of-a-field/m-p/220721#M64844</guid>
      <dc:creator>emamedov</dc:creator>
      <dc:date>2016-01-07T21:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to group and add the count for each value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-and-add-the-count-for-each-value-of-a-field/m-p/220722#M64845</link>
      <description>&lt;P&gt;Hi @emamedov,&lt;BR /&gt;
Have you tried using "stats count by" with the fields you are trying to aggregate?&lt;/P&gt;

&lt;P&gt;For example:&lt;BR /&gt;
eventtype=product-view|stats count by productname username&lt;/P&gt;

&lt;P&gt;As a more general example, if I run a search that includes this :&lt;BR /&gt;
...| stats count by (fieldA) (fieldB)&lt;BR /&gt;
then the results would show a count of how many (fieldB) items there are, per (fieldA) item. It seems like a search like this would give you view counts per user for each product.&lt;/P&gt;

&lt;P&gt;Here are some examples in the documentation that might help:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.3.1511/SearchReference/Stats#Use_Case_Examples"&gt;http://docs.splunk.com/Documentation/Splunk/6.3.1511/SearchReference/Stats#Use_Case_Examples&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Jan 2016 00:05:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-and-add-the-count-for-each-value-of-a-field/m-p/220722#M64845</guid>
      <dc:creator>frobinson_splun</dc:creator>
      <dc:date>2016-01-08T00:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to group and add the count for each value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-and-add-the-count-for-each-value-of-a-field/m-p/220723#M64846</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=product-view | chart count over username by productname
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And then if you want totals, you can do &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eventtype=product-view | chart count over username by productname | addtotals | addcoltotals labelfield=fieldA label=Totals
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Jan 2016 00:33:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-and-add-the-count-for-each-value-of-a-field/m-p/220723#M64846</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-01-08T00:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to group and add the count for each value of a field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-group-and-add-the-count-for-each-value-of-a-field/m-p/220724#M64847</link>
      <description>&lt;P&gt;Hello @emamedov,&lt;BR /&gt;
I ran into a similar problem and found a solution hidden in the splunk archives here. For your use case, try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; eventtype=product-view 
 | stats count by username, productname
 | stats list(username) as "User Name" list(count) as count by productname
 | rename productname as "Product Name"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Good luck and happy hunting!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2016 17:52:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-group-and-add-the-count-for-each-value-of-a-field/m-p/220724#M64847</guid>
      <dc:creator>dark_15</dc:creator>
      <dc:date>2016-01-12T17:52:25Z</dc:date>
    </item>
  </channel>
</rss>

