<?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 you return a conditional count and grand-total in a query? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441361#M125385</link>
    <description>&lt;P&gt;Thanks Vijeta for coming back to me. I ran this query and I am getting the correct grand total but the revisit number is much larger than expected. &lt;/P&gt;

&lt;P&gt;I get the 297 for the grand total but 247 for revisits which is too high. I am expecting around 117.&lt;/P&gt;

&lt;P&gt;Any idea why?&lt;/P&gt;</description>
    <pubDate>Wed, 19 Dec 2018 19:12:06 GMT</pubDate>
    <dc:creator>skribble5</dc:creator>
    <dc:date>2018-12-19T19:12:06Z</dc:date>
    <item>
      <title>How do you return a conditional count and grand-total in a query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441359#M125383</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;

&lt;P&gt;Novice here. I have two separate queries that are doing a simple calculation each, but I would like to combine them.  What would be the best way to do this?&lt;/P&gt;

&lt;P&gt;The first query returns the distinct number of users within a data source:&lt;/P&gt;

&lt;P&gt;Here is the result which says that the campaign "DM664023" had 297 recipients. The recipients are in the field "user_only"&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6270i37C5C0E8BFBD4FED/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;The query used to get to that result is: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="xxx" source="yyy" 
campaign_delivery="DM664023"
| stats dc(user_only) as distinctRecipients by campaign_delivery
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then, the second query returns the number of users who have more than one record in the data-source. If a user only has 1 record in the data source, then that person only access the campaign once. If the user has &amp;gt; 1 record in the data source, then that person revisited the campaign. &lt;/P&gt;

&lt;P&gt;The second query returns the number of revisits. Here is the result which says that the campaign DM664023 had 117 revisits.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6271iF1938773645C38CA/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;The query used to get to second result is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="xxx" source="yyy" 
campaign_delivery="DM664023"
| stats count by user_only | where count &amp;gt; 1
| chart count as "Revisits"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ideally, I want one search which returns the following:&lt;/P&gt;

&lt;P&gt;"campaign" |    "# total ppl who accessed the campaign" |   "number of people who accessed campaign more than once  | % of people who revisited campaign&lt;BR /&gt;
DM664023  |     297     |   117     |   39.39%&lt;BR /&gt;
campaign2  |    x      |    y         |   y/x&lt;BR /&gt;
campaign3  |    a         |  b      |    b/a&lt;/P&gt;

&lt;P&gt;Any help will be greatly appreciated!&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 16:30:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441359#M125383</guid>
      <dc:creator>skribble5</dc:creator>
      <dc:date>2018-12-19T16:30:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do you return a conditional count and grand-total in a query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441360#M125384</link>
      <description>&lt;P&gt;Try this if it works-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="xxx" source="yyy" 
 campaign_delivery="DM664023"
 | eventstats count as revisit by user_only | stats dc(user_only) as distinctRecipients , count(eval(revisit&amp;gt;1)) as Revisit by campaign_delivery| eval perc= Revisit/distinctRecipients*100 | table campaign_delivery Revisit distinctRecipients perc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Dec 2018 17:05:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441360#M125384</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2018-12-19T17:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do you return a conditional count and grand-total in a query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441361#M125385</link>
      <description>&lt;P&gt;Thanks Vijeta for coming back to me. I ran this query and I am getting the correct grand total but the revisit number is much larger than expected. &lt;/P&gt;

&lt;P&gt;I get the 297 for the grand total but 247 for revisits which is too high. I am expecting around 117.&lt;/P&gt;

&lt;P&gt;Any idea why?&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 19:12:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441361#M125385</guid>
      <dc:creator>skribble5</dc:creator>
      <dc:date>2018-12-19T19:12:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do you return a conditional count and grand-total in a query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441362#M125386</link>
      <description>&lt;P&gt;Try &lt;CODE&gt;dedup user_only&lt;/CODE&gt; before stats command &lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 19:25:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441362#M125386</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2018-12-19T19:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: How do you return a conditional count and grand-total in a query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441363#M125387</link>
      <description>&lt;P&gt;That worked beautifully. Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 19:38:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-return-a-conditional-count-and-grand-total-in-a-query/m-p/441363#M125387</guid>
      <dc:creator>skribble5</dc:creator>
      <dc:date>2018-12-19T19:38:48Z</dc:date>
    </item>
  </channel>
</rss>

