<?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 count the number of each distinct Product in the subsearch Splunk example? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348610#M5526</link>
    <description>&lt;P&gt;You can get that by simple adding to your search.:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by productID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 14 Mar 2018 08:14:16 GMT</pubDate>
    <dc:creator>p_gurav</dc:creator>
    <dc:date>2018-03-14T08:14:16Z</dc:date>
    <item>
      <title>How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348603#M5519</link>
      <description>&lt;P&gt;Hello, &lt;/P&gt;

&lt;P&gt;I am new to Splunk and trying to figure out how subsearches work.&lt;BR /&gt;
My problem is : How to count the number of each distinct Product in this Splunk query example:&lt;/P&gt;

&lt;P&gt;:sourcetype=access_* status=200 action=purchase [search sourcetype=access_* status=200 action=purchase | top limit=1 clientip | table clientip] | stats count AS "Total Purchased", dc(productId) AS "Total Products", values(productId) AS "Products ID" by clientip | rename clientip AS "VIP Customer".&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:26:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348603#M5519</guid>
      <dc:creator>sama_hp</dc:creator>
      <dc:date>2020-09-29T18:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348604#M5520</link>
      <description>&lt;P&gt;The main thing to remember about subsearches is they execute before the rest of the query.  The results of the subsearch then become part of the main query as if you had typed them yourself.&lt;/P&gt;

&lt;P&gt;In your example, the subsearch looks for the most common IP address that made a purchase.  The main search then looks for all purchases by that IP address and calculates the number of purchases, number of products purchased, and lists those products.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 01:33:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348604#M5520</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-03-14T01:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348605#M5521</link>
      <description>&lt;P&gt;Thanks for the explanation. However I am looking for a detail list of the count of each product that has been bought by the most common IP address.&lt;/P&gt;

&lt;P&gt;I have tried different ways like below query but it does not produce the result that I want.&lt;/P&gt;

&lt;P&gt;sourcetype=access_* status=200 action=purchase [search sourcetype=access_* status=200 action=purchase | top limit=1 clientip | table clientip] | stats count AS "Total Purchased", dc(productId) AS "Total Products", values(productId) AS "Products ID", count(values(productId)) by clientip | rename clientip AS "VIP Customer"&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:26:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348605#M5521</guid>
      <dc:creator>sama_hp</dc:creator>
      <dc:date>2020-09-29T18:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348606#M5522</link>
      <description>&lt;P&gt;I think that there is no option other than totaling separately for each product.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(your search)
| stats count as "Total Products" by clientip,productId
| addcoltotals labelfield=productId label="Total Purchased"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Mar 2018 07:34:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348606#M5522</guid>
      <dc:creator>HiroshiSatoh</dc:creator>
      <dc:date>2018-03-14T07:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348607#M5523</link>
      <description>&lt;P&gt;I have tried this query too. But It does not return anything!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 07:42:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348607#M5523</guid>
      <dc:creator>sama_hp</dc:creator>
      <dc:date>2018-03-14T07:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348608#M5524</link>
      <description>&lt;P&gt;do you want count of purchase happened  by each productID?&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 07:55:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348608#M5524</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2018-03-14T07:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348609#M5525</link>
      <description>&lt;P&gt;Correct! I need the count of purchase happened by each productID.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 08:02:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348609#M5525</guid>
      <dc:creator>sama_hp</dc:creator>
      <dc:date>2018-03-14T08:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348610#M5526</link>
      <description>&lt;P&gt;You can get that by simple adding to your search.:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by productID
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Mar 2018 08:14:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348610#M5526</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2018-03-14T08:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348611#M5527</link>
      <description>&lt;P&gt;This is what I tried at first:&lt;BR /&gt;
sourcetype=access_* status=200 action=purchase [search sourcetype=access_* status=200 action=purchase | top limit=1 clientip | table clientip] | stats count AS "Total Purchased", dc(productId) AS "Total Products", values(productId) AS "Products ID" by clientip | rename clientip AS "VIP Customer"| stats count by productId&lt;/P&gt;

&lt;P&gt;which doesn't work!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:26:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348611#M5527</guid>
      <dc:creator>sama_hp</dc:creator>
      <dc:date>2020-09-29T18:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348612#M5528</link>
      <description>&lt;P&gt;You already rename productID , so try : &lt;BR /&gt;
    sourcetype=access_ status=200 action=purchase [search sourcetype=access_ status=200 action=purchase | top limit=1 clientip | table clientip] | stats count by productID &lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 08:31:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348612#M5528</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2018-03-14T08:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348613#M5529</link>
      <description>&lt;P&gt;I don't Think that matters since still no result found!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 08:36:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348613#M5529</guid>
      <dc:creator>sama_hp</dc:creator>
      <dc:date>2018-03-14T08:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348614#M5530</link>
      <description>&lt;P&gt;You can try use the MAP command like this: &lt;/P&gt;

&lt;P&gt;index=whatever sourcetype=whatever status=200 action=purchase&lt;BR /&gt;
| top limit=1 clientip&lt;BR /&gt;
| map search="search index=whatever sourcetype=whatever clientip=$clientip$ | stats count as totalPurchased by productId"&lt;/P&gt;

&lt;P&gt;What this does is it will find out the top client IP and then pass that value to the map search and run that and get the info you want. This might not work as I've not tested the logic or anything yet but even if it doesn't, hopefully it points you in the right direction or something. &lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 11:19:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348614#M5530</guid>
      <dc:creator>Robbie1194</dc:creator>
      <dc:date>2018-03-14T11:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348615#M5531</link>
      <description>&lt;P&gt;If you wanted to do this for the top 10 customers then you could just change the limit to 10 in the top command etc etc. &lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2018 11:20:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348615#M5531</guid>
      <dc:creator>Robbie1194</dc:creator>
      <dc:date>2018-03-14T11:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of each distinct Product in the subsearch Splunk example?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348616#M5532</link>
      <description>&lt;P&gt;Thanks Robbie. &lt;BR /&gt;
I tried the following query based on your suggestion but i'm not sure if I am getting the correct result as the sum of the detailedPurchase does not match the Total Purchased.&lt;BR /&gt;
Also the result only returns the map search but not the other statistics that I'm asking in my query!&lt;/P&gt;

&lt;P&gt;sourcetype=access_* status=200 action=purchase [search sourcetype=access_* status=200 action=purchase | top limit=1 clientip | table clientip] | stats count AS "Total Purchased", dc(productId) AS "Total Products", values(productId) AS "Products ID" by clientip | map search="search sourcetype=Access_* clientip=$clientip$ |stats count AS detaiedPurchase by productId"&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:27:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/How-to-count-the-number-of-each-distinct-Product-in-the/m-p/348616#M5532</guid>
      <dc:creator>sama_hp</dc:creator>
      <dc:date>2020-09-29T18:27:05Z</dc:date>
    </item>
  </channel>
</rss>

