<?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 How to get the correct count records instead of counting the field name twice? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355073#M105049</link>
    <description>&lt;P&gt;Here is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="WinEventLog:Security" EventCode="4723" OR EventCode="529" | eval UserName=coalesce(User_Name,Account_Name) | stats count by UserName |sort -count |head 10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem is that the field &lt;CODE&gt;"Account_Name"&lt;/CODE&gt; appears more than once in the record, so the count is effectively doubled.  How can I get the correct count of the records instead of counting the field name twice?&lt;/P&gt;</description>
    <pubDate>Sat, 03 Feb 2018 17:00:57 GMT</pubDate>
    <dc:creator>ksbuchanan</dc:creator>
    <dc:date>2018-02-03T17:00:57Z</dc:date>
    <item>
      <title>How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355073#M105049</link>
      <description>&lt;P&gt;Here is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="WinEventLog:Security" EventCode="4723" OR EventCode="529" | eval UserName=coalesce(User_Name,Account_Name) | stats count by UserName |sort -count |head 10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem is that the field &lt;CODE&gt;"Account_Name"&lt;/CODE&gt; appears more than once in the record, so the count is effectively doubled.  How can I get the correct count of the records instead of counting the field name twice?&lt;/P&gt;</description>
      <pubDate>Sat, 03 Feb 2018 17:00:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355073#M105049</guid>
      <dc:creator>ksbuchanan</dc:creator>
      <dc:date>2018-02-03T17:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355074#M105050</link>
      <description>&lt;P&gt;In your &lt;CODE&gt;coalesce&lt;/CODE&gt; you can use &lt;CODE&gt;mvindex&lt;/CODE&gt; to grab just the first occurrence of &lt;CODE&gt;Account_Name&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval UserName=coalesce(User_Name,mvindex(Account_Name, 0))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 03 Feb 2018 23:09:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355074#M105050</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-03T23:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355075#M105051</link>
      <description>&lt;P&gt;host="rh-dc*" EventCode=4723 &lt;BR /&gt;
| eval UserName=coalesce(User_Name,mvindex(Account_Name, 0)) &lt;BR /&gt;
|  stats count(Account_Name) by Account_Name&lt;BR /&gt;
| sort -count(Account_Name)&lt;/P&gt;

&lt;P&gt;This yields this result:&lt;BR /&gt;
Account_Name    count(Account_Name)&lt;BR /&gt;
KINKI   12&lt;BR /&gt;
ROSCO   8&lt;BR /&gt;
ADAAN   4&lt;/P&gt;

&lt;P&gt;The problem, is that there are only 3 actual records for the Account_Name: KINKI&lt;/P&gt;

&lt;P&gt;why is it multiplying the results?    Granted, the record has 2 fields that are called "Account_Name" which contain "KINKI"&lt;/P&gt;

&lt;P&gt;I appreciate your help...but I am confused about how to get it to count the "just the first "occurrence" of the "Account_Name" field.   &lt;/P&gt;

&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:53:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355075#M105051</guid>
      <dc:creator>ksbuchanan</dc:creator>
      <dc:date>2020-09-29T17:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355076#M105052</link>
      <description>&lt;P&gt;&lt;CODE&gt;count(Account_Name) BY Account_Name&lt;/CODE&gt; will count the number of values seen in the &lt;CODE&gt;Account_Name&lt;/CODE&gt; field, not the number of events where that &lt;CODE&gt;Account_Name&lt;/CODE&gt; was seen.&lt;/P&gt;

&lt;P&gt;To get the event count per &lt;CODE&gt;Account_Name&lt;/CODE&gt;, use &lt;CODE&gt;stats count BY Account_Name‘.  Notice the lack of&lt;/CODE&gt;()` in this example.&lt;/P&gt;

&lt;P&gt;Also, you caolesced to &lt;CODE&gt;User_Name&lt;/CODE&gt;, but counted by &lt;CODE&gt;Account_Name&lt;/CODE&gt;. I can’t imagine this is actually what you wanted.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 04:33:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355076#M105052</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-04T04:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355077#M105053</link>
      <description>&lt;P&gt;micahkemp:  I tried you solution, but the resulting count is 6, but the number of records is 3.  &lt;/P&gt;

&lt;P&gt;The Windows event log uses the Account_Name field twice in the record, and the search statement is counting each one of the field occurrences.  So, all the counts are doubled. &lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 13:17:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355077#M105053</guid>
      <dc:creator>ksbuchanan</dc:creator>
      <dc:date>2018-02-04T13:17:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355078#M105054</link>
      <description>&lt;P&gt;i found a solution   i am doing a distinct count on the record number, and that returns the correct number of records&lt;/P&gt;

&lt;P&gt;host="rh-dc*" EventCode=4723 &lt;BR /&gt;
|  stats dc(RecordNumber) by Account_Name&lt;BR /&gt;
| sort -count&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 16:19:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355078#M105054</guid>
      <dc:creator>ksbuchanan</dc:creator>
      <dc:date>2018-02-04T16:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355079#M105055</link>
      <description>&lt;P&gt;i found a solution.   i am doing a distinct count on the record number, and that returns the correct number of records&lt;/P&gt;

&lt;P&gt;host="rh-dc*" EventCode=4723 &lt;BR /&gt;
| stats dc(RecordNumber) by Account_Name&lt;BR /&gt;
| sort -count&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 16:21:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355079#M105055</guid>
      <dc:creator>ksbuchanan</dc:creator>
      <dc:date>2018-02-04T16:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355080#M105056</link>
      <description>&lt;P&gt;Excellent.  You my consider converting your comment to an answer and accepting it so that this question no longer appears open and others have an easier time finding the correct answer.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 16:30:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355080#M105056</guid>
      <dc:creator>micahkemp</dc:creator>
      <dc:date>2018-02-04T16:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355081#M105057</link>
      <description>&lt;P&gt;@ksbuchanan If your problem is resolved, please accept an answer to help future readers.&lt;/P&gt;</description>
      <pubDate>Sun, 04 Feb 2018 19:17:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355081#M105057</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2018-02-04T19:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355082#M105058</link>
      <description>&lt;P&gt;I downvoted this post because this solution didn't work.  i tried it and it gave the same answer (which was 2x the number of actual records).&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 06:14:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355082#M105058</guid>
      <dc:creator>ksbuchanan</dc:creator>
      <dc:date>2018-02-13T06:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355083#M105059</link>
      <description>&lt;P&gt;@ksbuchanon,&lt;/P&gt;

&lt;P&gt;Thank you for participating in Answers!  Having users that ask questions and help answer them are what makes our community so great!&lt;/P&gt;

&lt;P&gt;We here in Answers often deal with very complex, vague questions over data and problems that aren't well defined.  These often require multiple layers of comments and attempts to find a "best" answer for the questioner's problem.  We really think this is one of the things that sets this community apart from others - our inclusion of all people who are trying to help and the effort we will often put toward finding you the answer you need.&lt;/P&gt;

&lt;P&gt;So, In order to encourage as much participation as possible we prefer to: &lt;BR /&gt;
   &lt;STRONG&gt;Accept the "most right" answer&lt;/STRONG&gt; if it solved your problem, &lt;BR /&gt;
   &lt;STRONG&gt;Liberally upvote&lt;/STRONG&gt; comments or other answers that were helpful.&lt;/P&gt;

&lt;P&gt;In that same spirit, we reserve downvoting an answer for only if it's possibly harmful to a users system, and not if it just didn't quite answer your problem as well as it could have.&lt;/P&gt;

&lt;P&gt;Many thanks, and Happy Splunking!&lt;BR /&gt;
-Rich&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 17:30:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355083#M105059</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2018-02-13T17:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the correct count records instead of counting the field name twice?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355084#M105060</link>
      <description>&lt;P&gt;Hi @ksbuchanan&lt;/P&gt;

&lt;P&gt;Glad you found a solution to your question &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Just fyi for this Splunk community forum, please reserve downvotes for suggestions that could be harmful in a Splunk environment or is against known best practices. If you have feedback on someone's post, just commenting on it will be more constructive instead of making people lose karma points who was just trying to help out. For the solution(s) that do work, upvote those so they make it up to the top of the list for visibility.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 17:32:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-correct-count-records-instead-of-counting-the/m-p/355084#M105060</guid>
      <dc:creator>ppablo</dc:creator>
      <dc:date>2018-02-13T17:32:22Z</dc:date>
    </item>
  </channel>
</rss>

