<?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 distinct count using stats and eval in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245705#M73235</link>
    <description>&lt;P&gt;I am slowly going insane trying to figure out how to remove duplicates from an eval statement.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;where acc="Inc" AND Stage = "NewBusiness"  | stats dc(quoteNumber) AS Quotes count(eval(processStatus="ManualRatingRequired")) as Referrals |eval perc=round(Referrals/Quotes*100, 1)."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem I am having is that whilst I have been able to remove the duplicates for the first stats (Quotes) I am unable to remove them for the eval component. If I use distinct count then only 1 even is returned and if i use distinct count with a filter by quoteNumber then all works and the duplicates are removed... however the results are returned as separate events in table format.&lt;/P&gt;

&lt;P&gt;I am after distinct count of all quotes / a distinct count of all quotes that have a processStatus of Referred.&lt;/P&gt;

&lt;P&gt;Sounds easy (and it probably is) but it is doing my head in and I am not getting any closer to a solution.... so for the sake of my sanity any help will be great appreciated.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Alastair&lt;/P&gt;</description>
    <pubDate>Wed, 23 Nov 2016 03:34:26 GMT</pubDate>
    <dc:creator>ahogbin</dc:creator>
    <dc:date>2016-11-23T03:34:26Z</dc:date>
    <item>
      <title>distinct count using stats and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245705#M73235</link>
      <description>&lt;P&gt;I am slowly going insane trying to figure out how to remove duplicates from an eval statement.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;where acc="Inc" AND Stage = "NewBusiness"  | stats dc(quoteNumber) AS Quotes count(eval(processStatus="ManualRatingRequired")) as Referrals |eval perc=round(Referrals/Quotes*100, 1)."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem I am having is that whilst I have been able to remove the duplicates for the first stats (Quotes) I am unable to remove them for the eval component. If I use distinct count then only 1 even is returned and if i use distinct count with a filter by quoteNumber then all works and the duplicates are removed... however the results are returned as separate events in table format.&lt;/P&gt;

&lt;P&gt;I am after distinct count of all quotes / a distinct count of all quotes that have a processStatus of Referred.&lt;/P&gt;

&lt;P&gt;Sounds easy (and it probably is) but it is doing my head in and I am not getting any closer to a solution.... so for the sake of my sanity any help will be great appreciated.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;

&lt;P&gt;Alastair&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 03:34:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245705#M73235</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2016-11-23T03:34:26Z</dc:date>
    </item>
    <item>
      <title>Re: distinct count using stats and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245706#M73236</link>
      <description>&lt;P&gt;Why don't you insert a &lt;CODE&gt;dedup&lt;/CODE&gt; just before you start going for your stats like this and see if that works for you:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;where acc="Inc" AND Stage = "NewBusiness"  
| dedup quoteNumber  processStatus
| stats dc(quoteNumber) AS Quotes count(eval(processStatus="ManualRatingRequired")) as Referrals |eval perc=round(Referrals/Quotes*100, 1)."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Updating as per comments&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;where acc="Inc" AND Stage = "NewBusiness"  
 | eventstats dc(quoteNumber) AS Quotes
 | dedup processStatus, quoteNumber
 |  stats values(Quotes) as UniqueQuotes count(eval(processStatus="ManualRatingRequired")) as Referrals 
 |eval perc=round(Referrals/UniqueQuotes*100, 1)."%"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 04:41:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245706#M73236</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-11-23T04:41:30Z</dc:date>
    </item>
    <item>
      <title>Re: distinct count using stats and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245707#M73237</link>
      <description>&lt;P&gt;Tried that.. the problem with the dedup is that it only returns the latest event and removes some of the events I am trying to included.&lt;/P&gt;

&lt;P&gt;Eg: If I do count of quotes for the current day I get 36. If I remove he duplicates I get 25.&lt;BR /&gt;
If I do the same for those quotes that have triggered a referral I end up with 17 (including duplicates) and 12 if I remove the duplicates.&lt;/P&gt;

&lt;P&gt;Using dedup and a count by processStatus gives me  only 10 referrals.&lt;/P&gt;

&lt;P&gt;For any quote there can be multiple entries&lt;/P&gt;

&lt;P&gt;QN1-  Referred&lt;BR /&gt;
QN1 - Completed&lt;BR /&gt;
QN1 - Closed&lt;BR /&gt;
QN2 - Completed&lt;BR /&gt;
QN2 - Closed&lt;/P&gt;

&lt;P&gt;Dedup returns QN1 - Closed (as this is the latest event).&lt;/P&gt;

&lt;P&gt;Is there a way to return a dc(Quotes) and a dc(Quotes) where status = Referred (eg using the above as a guide - 2 quotes and 1 referral)&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 05:15:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245707#M73237</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2016-11-23T05:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: distinct count using stats and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245708#M73238</link>
      <description>&lt;P&gt;I still think that this query should give you what's needed as it does a dedu on the &lt;CODE&gt;processStatus&lt;/CODE&gt; and &lt;CODE&gt;quoteNumber&lt;/CODE&gt; so there shouldn't be a reason for it to return only the last &lt;CODE&gt;closed&lt;/CODE&gt; event, but I have updated additional query which basically should do the same thing differently:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;where acc="Inc" AND Stage = "NewBusiness"  
 | dedup quoteNumber,  processStatus
 | stats dc(quoteNumber) AS Quotes count(eval(processStatus="ManualRatingRequired")) as Referrals |eval perc=round(Referrals/Quotes*100, 1)."%"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;where acc="Inc" AND Stage = "NewBusiness"  
  | eventstats dc(quoteNumber) AS Quotes
  | dedup processStatus, quoteNumber
  |  stats values(Quotes) as UniqueQuotes count(eval(processStatus="ManualRatingRequired")) as Referrals 
|eval perc=round(Referrals/UniqueQuotes*100, 1)."%"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 07:18:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245708#M73238</guid>
      <dc:creator>gokadroid</dc:creator>
      <dc:date>2016-11-23T07:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: distinct count using stats and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245709#M73239</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
Try the following search code using dedup command :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; where acc="Inc" AND Stage = "NewBusiness" |dedup quoteNumber | stats count(quoteNumber) AS Quotes count(eval(processStatus="ManualRatingRequired")) as Referrals |eval perc=round(Referrals/Quotes*100, 1)."%"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 12:45:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245709#M73239</guid>
      <dc:creator>chimell</dc:creator>
      <dc:date>2016-11-23T12:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: distinct count using stats and eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245710#M73240</link>
      <description>&lt;P&gt;Both work a treat.. thank you so much for your help.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;BR /&gt;
Alastair&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2016 04:03:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/distinct-count-using-stats-and-eval/m-p/245710#M73240</guid>
      <dc:creator>ahogbin</dc:creator>
      <dc:date>2016-11-25T04:03:03Z</dc:date>
    </item>
  </channel>
</rss>

