<?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 Calculate percentage from a join query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculate-percentage-from-a-join-query/m-p/106578#M27726</link>
    <description>&lt;P&gt;I need to calculate the percentage of products that I have searched for that exist in a specific product catalog.&lt;/P&gt;

&lt;P&gt;I have written an inner join, which gets all the product_ids from the search and does as inner join into the product catalog:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;sourcetype=products | fields product_id |join product_id [search sourcetype=catalogue |fields product_id ]  | stats count&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I added  &lt;STRONG&gt;stats count&lt;/STRONG&gt; which gives the number of products from the search in the catalog.&lt;/P&gt;

&lt;P&gt;How can I modify the query so it returns the count as a percentage of total products that were returned from the initial search?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 12:42:39 GMT</pubDate>
    <dc:creator>justjosh</dc:creator>
    <dc:date>2020-09-28T12:42:39Z</dc:date>
    <item>
      <title>Calculate percentage from a join query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-percentage-from-a-join-query/m-p/106578#M27726</link>
      <description>&lt;P&gt;I need to calculate the percentage of products that I have searched for that exist in a specific product catalog.&lt;/P&gt;

&lt;P&gt;I have written an inner join, which gets all the product_ids from the search and does as inner join into the product catalog:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;sourcetype=products | fields product_id |join product_id [search sourcetype=catalogue |fields product_id ]  | stats count&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I added  &lt;STRONG&gt;stats count&lt;/STRONG&gt; which gives the number of products from the search in the catalog.&lt;/P&gt;

&lt;P&gt;How can I modify the query so it returns the count as a percentage of total products that were returned from the initial search?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:42:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-percentage-from-a-join-query/m-p/106578#M27726</guid>
      <dc:creator>justjosh</dc:creator>
      <dc:date>2020-09-28T12:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate percentage from a join query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculate-percentage-from-a-join-query/m-p/106579#M27727</link>
      <description>&lt;P&gt;I'm not sure if there is some built-in function or command to get what you want, but I believe the following query will get you close:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=products
 | stats dc(product_id) as count by product_id
 | eventstats dc(product_id) as totalCount
 | join product_id [search sourcetype=catalogue]
 | stats count as lookupCount values(totalCount) as totalCount
 | eval percTotal=lookupCount/totalCount
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;OL&gt;
&lt;LI&gt;The first &lt;CODE&gt;stats&lt;/CODE&gt; line gets you a distinct list of product ids that will be needed later for the &lt;CODE&gt;join&lt;/CODE&gt;.&lt;/LI&gt;
&lt;LI&gt;The &lt;CODE&gt;eventstats&lt;/CODE&gt; line adds a count of the number of products found to each result from the previous &lt;CODE&gt;stats&lt;/CODE&gt;. This is needed later for the calculation of percentage of total products.&lt;/LI&gt;
&lt;LI&gt;The &lt;CODE&gt;join&lt;/CODE&gt; is basically the same except I removed the &lt;CODE&gt;fields&lt;/CODE&gt;.&lt;/LI&gt;
&lt;LI&gt;The next &lt;CODE&gt;stats&lt;/CODE&gt; line gets a count of the items found from the join as well as carrying over the totalCount from the previous results.&lt;/LI&gt;
&lt;LI&gt;The &lt;CODE&gt;eval&lt;/CODE&gt; gets your percentage of total products that were returned from the initial search.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Thu, 01 Nov 2012 14:37:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculate-percentage-from-a-join-query/m-p/106579#M27727</guid>
      <dc:creator>justgrumpy</dc:creator>
      <dc:date>2012-11-01T14:37:50Z</dc:date>
    </item>
  </channel>
</rss>

