<?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 search the distinct count of a field based on a condition, then calculate percentage? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271453#M81713</link>
    <description>&lt;P&gt;It is also subject to subsearch limits; my solution is not.&lt;/P&gt;</description>
    <pubDate>Tue, 13 Oct 2015 19:18:53 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-10-13T19:18:53Z</dc:date>
    <item>
      <title>How to search the distinct count of a field based on a condition, then calculate percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271449#M81709</link>
      <description>&lt;P&gt;Here is an example of my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Search | stats dc(eval(DISPLAYNAME)) AS Total,dc(eval(STATUS="Offline")) AS Offline| eval Percentage=round((100*(Total-Offline)/Total))."%" | fields - Total, Offline
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My goal is to take the total number of devices as referenced by the &lt;CODE&gt;dc(DISPLAYNAME)&lt;/CODE&gt;.  Then, I'd like to take the same number, but under the condition that the &lt;STRONG&gt;STATUS&lt;/STRONG&gt; field is equal to "Offline".  When I do the count, I get a correct number until the next data import, then it duplicates as it should.  Distinct count only returns a "1".  I guess I'm not quite sure how to eval the &lt;STRONG&gt;DISPLAYNAME&lt;/STRONG&gt; field again, but only for offline devices.&lt;/P&gt;

&lt;P&gt;Any help would be appreciated.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 18:03:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271449#M81709</guid>
      <dc:creator>jawebb</dc:creator>
      <dc:date>2015-10-13T18:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the distinct count of a field based on a condition, then calculate percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271450#M81710</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval DISPLAYNAMEforOFFLINES = if((STATUS="Offline"), DISPLAYNAME, null()) | stats dc(eval(DISPLAYNAME)) AS Total dc(DISPLAYNAMEforOFFLINES) AS Offline| eval Percentage=round((100*(Total-Offline)/Total))."%" | fields - Total, Offline
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Oct 2015 18:40:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271450#M81710</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-13T18:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the distinct count of a field based on a condition, then calculate percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271451#M81711</link>
      <description>&lt;P&gt;Thank you!  Works great.  I also found that the join command worked for me as well, but I prefer your way.&lt;/P&gt;

&lt;P&gt;Search | stats dc(eval(DISPLAYNAME)) AS Total| join [search "index" (STATUS=Offline) | stats dc(eval(DISPLAYNAME)) AS Offline] | eval Percentage=round((100*(Total-Offline)/Total))."%" | fields - Total, Offline&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 18:43:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271451#M81711</guid>
      <dc:creator>jawebb</dc:creator>
      <dc:date>2015-10-13T18:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the distinct count of a field based on a condition, then calculate percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271452#M81712</link>
      <description>&lt;P&gt;The &lt;CODE&gt;join&lt;/CODE&gt; approach would run the search twice, so it's not a great idea if avoidable (it is).&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 18:46:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271452#M81712</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-10-13T18:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to search the distinct count of a field based on a condition, then calculate percentage?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271453#M81713</link>
      <description>&lt;P&gt;It is also subject to subsearch limits; my solution is not.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Oct 2015 19:18:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-the-distinct-count-of-a-field-based-on-a-condition/m-p/271453#M81713</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-13T19:18:53Z</dc:date>
    </item>
  </channel>
</rss>

