<?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 Query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25921#M4923</link>
    <description>&lt;P&gt;So you're telling Splunk to give you a distinct count of Value 2, which is does.  (There are 3 distinct values) and a count of all items in Value 3, which is does.  (I'm assuming the '----' is actually NULL in your records, so again there are 3 values)  &lt;/P&gt;

&lt;P&gt;What I'm not sure about is what you want the count to be for Value 3.  Do you want a count of all records (what your query asks for) or a distinct count?  (What your expected result set shows)  I'm not sure why you're not using dc for both counts.&lt;/P&gt;

&lt;P&gt;Now, if the '----' is actually an empty field, it won't be included in the count.  So perhaps you're expecting it to be included?  (That would cause a dc(Value 3) to return 2 like your expected results)  If so, you can fillnull to give all nulls some value which would then be counted.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | fillnull value=NULL "value 3" | chart dc(value 2) dc(value 3) by store
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 07 Nov 2012 16:33:23 GMT</pubDate>
    <dc:creator>emiller42</dc:creator>
    <dc:date>2012-11-07T16:33:23Z</dc:date>
    <item>
      <title>Distinct Count Query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25918#M4920</link>
      <description>&lt;P&gt;I've looked around for answers on this, but unfortunately I've not found an answer to date. I have a list of data, but some of this is duplicate and as such I need to remove a whole row rather than just that value itself, ie:&lt;/P&gt;

&lt;P&gt;Store     Value 2      Value 3&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_1   Black&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_2   Black&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_3   ----&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_1   Black       &lt;/P&gt;

&lt;P&gt;What I would like to do is chart this so that I have:&lt;/P&gt;

&lt;P&gt;Store     Count of Value 2 (Unique) Count of Value 3&lt;BR /&gt;
Store 1  3                                       2&lt;/P&gt;

&lt;P&gt;When I use &lt;/P&gt;

&lt;P&gt;... | chart dc(value 2), count (value 3) by store&lt;/P&gt;

&lt;P&gt;It omits only the duplicate value in Value 2, but my count in value 3 is too high, ie:&lt;/P&gt;

&lt;P&gt;Store     Count of Value 2 (Unique) Count of Value 3&lt;BR /&gt;
Store 1  3                                       3&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Hi - Sorry, I think the "---" is actually empty in my data. So that part should be okay.&lt;/P&gt;

&lt;P&gt;If I extend the values for two more line:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Store     Value 2      Value 3&lt;/STRONG&gt; &lt;BR /&gt;
Store 1  Device_1   Black&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_2   Black&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_3&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_1   Black&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_1   Black&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_4   Black     &lt;/P&gt;

&lt;P&gt;If I exported the data to Excel, I would initially filter all of the results so that I only had unique values in Value 2:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Store     Value 2      Value 3&lt;/STRONG&gt; &lt;BR /&gt;
Store 1  Device_1   Black&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_2   Black&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_3&lt;BR /&gt;&lt;BR /&gt;
Store 1  Device_4   Black     &lt;/P&gt;

&lt;P&gt;I would then run a pivot table which would show me the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;           Value 2      Value 3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Store 1     4               3&lt;/P&gt;

&lt;P&gt;So essentially, I want to remove any duplicate "lines" based on Value 2.&lt;/P&gt;

&lt;P&gt;I hope that makes more sense. Sorry though.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:45:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25918#M4920</guid>
      <dc:creator>shonky</dc:creator>
      <dc:date>2020-09-28T12:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25919#M4921</link>
      <description>&lt;P&gt;In your sample data, I see 3 lines with a value for Value 3, so I don't follow why you would like the count to be 2?&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2012 08:59:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25919#M4921</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-11-07T08:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25920#M4922</link>
      <description>&lt;P&gt;Because the the Value 2 is a duplicate.&lt;/P&gt;

&lt;P&gt;Essentially I only want to count the unique devices. Line 4 - Store 1, Device 1, Black - has already showed in my logs.&lt;/P&gt;

&lt;P&gt;Think of it as being like a repeat visitor to a website. It might show his IP address and then other information about the visitor. I don't want to count the other information twice as the visitor has already been there.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2012 16:24:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25920#M4922</guid>
      <dc:creator>shonky</dc:creator>
      <dc:date>2012-11-07T16:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25921#M4923</link>
      <description>&lt;P&gt;So you're telling Splunk to give you a distinct count of Value 2, which is does.  (There are 3 distinct values) and a count of all items in Value 3, which is does.  (I'm assuming the '----' is actually NULL in your records, so again there are 3 values)  &lt;/P&gt;

&lt;P&gt;What I'm not sure about is what you want the count to be for Value 3.  Do you want a count of all records (what your query asks for) or a distinct count?  (What your expected result set shows)  I'm not sure why you're not using dc for both counts.&lt;/P&gt;

&lt;P&gt;Now, if the '----' is actually an empty field, it won't be included in the count.  So perhaps you're expecting it to be included?  (That would cause a dc(Value 3) to return 2 like your expected results)  If so, you can fillnull to give all nulls some value which would then be counted.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | fillnull value=NULL "value 3" | chart dc(value 2) dc(value 3) by store
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Nov 2012 16:33:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25921#M4923</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2012-11-07T16:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25922#M4924</link>
      <description>&lt;P&gt;I updated my question. I think I need to do a filter on my data before I count it - ie remove the unique values based on value 2 and then do the count. Just not sure how to remove the duplicate values first.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2012 16:44:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25922#M4924</guid>
      <dc:creator>shonky</dc:creator>
      <dc:date>2012-11-07T16:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25923#M4925</link>
      <description>&lt;P&gt;So I'm assuming each Value 2 can only have one possible Value 3? (Including null)  If so, the dedup command would fix this for you.  &lt;/P&gt;

&lt;P&gt;... | dedup "value 2" | chart count(value 2) count(value 3)&lt;/P&gt;

&lt;P&gt;Would get you what you're looking for in the example.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2012 17:00:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25923#M4925</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2012-11-07T17:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25924#M4926</link>
      <description>&lt;P&gt;I was going to say no, that it can have more than 1 answer. But thinking about it, I think you may be right if I limit my time span to a short enough period. I will give it a go and come back and rate your answer. I think it should work. My own fault for not figuring this one out.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2012 17:06:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25924#M4926</guid>
      <dc:creator>shonky</dc:creator>
      <dc:date>2012-11-07T17:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Distinct Count Query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25925#M4927</link>
      <description>&lt;P&gt;If it can have multiple values, then you can simply&lt;/P&gt;

&lt;P&gt;... | dedup store "value 2" "value 3" | chart count(value 2) count(value 3) by store&lt;/P&gt;

&lt;P&gt;and that should get what you're looking for.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Nov 2012 17:08:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Distinct-Count-Query/m-p/25925#M4927</guid>
      <dc:creator>emiller42</dc:creator>
      <dc:date>2012-11-07T17:08:27Z</dc:date>
    </item>
  </channel>
</rss>

