<?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 calculate a percentage of distinct id's from a group of events which have never had a field matching a certain value? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-a-percentage-of-distinct-id-s-from-a-group-of/m-p/360346#M106523</link>
    <description>&lt;P&gt;Would something like this run anywhere search work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| append [| makeresults | eval id=1, status="SUCCEEDED"]
| append [| makeresults | eval id=1, status="FAILED"]
| append [| makeresults | eval id=2, status="FAILED"]
| stats values(status) AS status BY id
| eval only_failed=if(mvcount(status)=1 AND status!="SUCCEEDED", "YES", "NO")
| stats count BY only_failed
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And if you want to turn that into a percentage of failed over the total:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats sum(count) AS total_count
| eval percentage_of_total=round(count/total_count, 2)*100
| search only_failed="YES"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Feb 2018 20:02:37 GMT</pubDate>
    <dc:creator>micahkemp</dc:creator>
    <dc:date>2018-02-07T20:02:37Z</dc:date>
    <item>
      <title>How to calculate a percentage of distinct id's from a group of events which have never had a field matching a certain value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-a-percentage-of-distinct-id-s-from-a-group-of/m-p/360345#M106522</link>
      <description>&lt;P&gt;I have a group of log entries with an id field, and a status field. For a given id, over a given amount of time, status can equal failed a number of times, and that's ok, so long as there has been at least one success. What I want is a percentage of distinct id's which have never had a single success over the given period of time.&lt;/P&gt;

&lt;P&gt;I had come up with this search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="index" source="source" requestType="TYPE"  | where status="SUCCEEDED" | stats dc(id) as successCount | append [ search index="index" source="source" requestType="TYPE" | stats dc(id) as totalCount ]  | stats values(successCount) as sc values(totalCount) as tc | eval successRate = (sc/tc*100) | fields successRate
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, after digging into results today based on the resulting percentages, I feel as though the results of it might not be accurate.&lt;/P&gt;

&lt;P&gt;I can get a stats table with results that I can sort to show me the ids with 0 successes, with this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="index" source="source" requestType="TYPE"  | eval successId = if((status="SUCCEEDED"),1,0) | eval failId = if((status!="SUCCEEDED"),1,0) | stats sum(successId) as successes, sum(failId) as fails, values(failureMessage) by id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So what I'm looking to do is a search that will give me a % of id's that did not ever have a status of "SUCCEEDED" over the given time period. I can't seem to get the results of the above 'stats' into something correctly that can count id's that have successes == 0 and divide it by distinct id's.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 19:46:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-a-percentage-of-distinct-id-s-from-a-group-of/m-p/360345#M106522</guid>
      <dc:creator>dg_fuze</dc:creator>
      <dc:date>2018-02-07T19:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a percentage of distinct id's from a group of events which have never had a field matching a certain value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-a-percentage-of-distinct-id-s-from-a-group-of/m-p/360346#M106523</link>
      <description>&lt;P&gt;Would something like this run anywhere search work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| append [| makeresults | eval id=1, status="SUCCEEDED"]
| append [| makeresults | eval id=1, status="FAILED"]
| append [| makeresults | eval id=2, status="FAILED"]
| stats values(status) AS status BY id
| eval only_failed=if(mvcount(status)=1 AND status!="SUCCEEDED", "YES", "NO")
| stats count BY only_failed
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And if you want to turn that into a percentage of failed over the total:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats sum(count) AS total_count
| eval percentage_of_total=round(count/total_count, 2)*100
| search only_failed="YES"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:02:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-a-percentage-of-distinct-id-s-from-a-group-of/m-p/360346#M106523</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-07T20:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a percentage of distinct id's from a group of events which have never had a field matching a certain value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-a-percentage-of-distinct-id-s-from-a-group-of/m-p/360347#M106524</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="index" source="source" requestType="TYPE" 
| stats values(status) as status by id
| eval success=if(isnotnull(mvfind(status,"SUCCEEDED")),1,0)
| stats sum(success) as success count as total
| eval "No Success %"=round((success*100/total),2) 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:34:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-a-percentage-of-distinct-id-s-from-a-group-of/m-p/360347#M106524</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-02-07T20:34:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate a percentage of distinct id's from a group of events which have never had a field matching a certain value?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-a-percentage-of-distinct-id-s-from-a-group-of/m-p/360348#M106525</link>
      <description>&lt;P&gt;Thank you! Works great!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Feb 2018 20:35:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-a-percentage-of-distinct-id-s-from-a-group-of/m-p/360348#M106525</guid>
      <dc:creator>dg_fuze</dc:creator>
      <dc:date>2018-02-07T20:35:13Z</dc:date>
    </item>
  </channel>
</rss>

