<?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: Distinct Count Where... in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204601#M59447</link>
    <description>&lt;P&gt;Have a look at the edit. Furthermore, make sure all the cases match, so "Yes" and "yes" are not the same here. Check your data which you need (same for field names).&lt;/P&gt;</description>
    <pubDate>Thu, 03 Nov 2016 15:13:31 GMT</pubDate>
    <dc:creator>gwobben</dc:creator>
    <dc:date>2016-11-03T15:13:31Z</dc:date>
    <item>
      <title>Distinct Count Where...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204596#M59442</link>
      <description>&lt;P&gt;Hey people,&lt;/P&gt;

&lt;P&gt;I'm trying to get multiple "distinct count where..." working but don't know where to start.&lt;/P&gt;

&lt;P&gt;The idea is something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="servers"
|stats 
     where("Agent1" = "Yes", dc(Hostname))  as "Agent1 Installed"
     where("Agent2" = "Yes", dc(Hostname))  as "Agent2 Installed"
     where("Agent3" = "Yes", dc(Hostname))  as "Agent3 Installed"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The data in the file is set up like this and can't be changed &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Patch|Hostname|Agent1|Agent2|Agent3
123  |host1   |yes   |yes   |no
234  |host2   |yes   |no    |no
345  |host3   |no    |no    |no
456  |host1   |no    |yes   |yes
567  |host3   |yes   |yes   |yes
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The idea is to get the number of hosts with the Agent installed with all patches.&lt;BR /&gt;
Any help will be greatly appreciated!&lt;/P&gt;

&lt;P&gt;┈┈┈┈┈┈▕▔╲&lt;BR /&gt;
┈┈┈┈┈┈┈▏▕&lt;BR /&gt;
┈┈┈┈┈┈┈▏▕▂▂▂&lt;BR /&gt;
▂▂▂▂▂▂╱┈▕▂▂▂▏&lt;BR /&gt;
▉▉▉▉▉┈┈┈▕▂▂▂▏&lt;BR /&gt;
▉▉▉▉▉┈┈┈▕▂▂▂▏&lt;BR /&gt;
▔▔▔▔▔▔╲▂▕▂▂▂I&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 14:38:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204596#M59442</guid>
      <dc:creator>singhh4</dc:creator>
      <dc:date>2016-11-03T14:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Where...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204597#M59443</link>
      <description>&lt;P&gt;What is it you would like to count by? Distinct count of "Patch" by Hostname, per agent?  Try something like this:&lt;/P&gt;

&lt;P&gt;EDIT: Remove the quotes around AgentX, otherwise they'll be interpreted as strings.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="servers"
| stats 
       dc(eval(if(Agent1 = "Yes", Hostname, NULL)))  as "Agent1 Installed"
       dc(eval(if(Agent2 = "Yes", Hostname, NULL)))  as "Agent2 Installed"
       dc(eval(if(Agent3 = "Yes", Hostname, NULL)))  as "Agent3 Installed"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Nov 2016 14:48:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204597#M59443</guid>
      <dc:creator>gwobben</dc:creator>
      <dc:date>2016-11-03T14:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Where...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204598#M59444</link>
      <description>&lt;P&gt;What should be the expected output for your sample data?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 14:58:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204598#M59444</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-11-03T14:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Where...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204599#M59445</link>
      <description>&lt;P&gt;Not really counting by anything. I just need a count of distinct hosts for an agent where agent = Yes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Agent    |Hosts
agent1  |132
agent2  |304
agent3  |247
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I tried the search and it gave me 0's&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 15:10:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204599#M59445</guid>
      <dc:creator>singhh4</dc:creator>
      <dc:date>2016-11-03T15:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Where...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204600#M59446</link>
      <description>&lt;PRE&gt;&lt;CODE&gt; Agent    |Hosts
 agent1  |132
 agent2  |304
 agent3  |247
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I just need a count of distinct hosts for an agent where agent = Yes.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 15:11:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204600#M59446</guid>
      <dc:creator>singhh4</dc:creator>
      <dc:date>2016-11-03T15:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Where...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204601#M59447</link>
      <description>&lt;P&gt;Have a look at the edit. Furthermore, make sure all the cases match, so "Yes" and "yes" are not the same here. Check your data which you need (same for field names).&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 15:13:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204601#M59447</guid>
      <dc:creator>gwobben</dc:creator>
      <dc:date>2016-11-03T15:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Where...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204602#M59448</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="servers" 
| eval Agent=if(Agent1="yes","Agent1","") 
| eval Agent=Agent."#".if(Agent2="yes","Agent2","") 
| eval Agent=Agent."#".if(Agent3="yes","Agent3","") 
| stats dc(Hostname) by Agent
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Nov 2016 15:57:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204602#M59448</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-11-03T15:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Where...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204603#M59449</link>
      <description>&lt;P&gt;That would be simpler then. Below line in your question was making it complex/confusing.&lt;/P&gt;

&lt;P&gt;The idea is to get the number of hosts with the Agent installed &lt;STRONG&gt;with all patches&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 15:58:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Where/m-p/204603#M59449</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-11-03T15:58:49Z</dc:date>
    </item>
  </channel>
</rss>

