<?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: Count a field by another one and removes duplicates in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-field-by-another-one-and-removes-duplicates/m-p/607390#M211168</link>
    <description>&lt;P&gt;You were so very close.&amp;nbsp; Use the &lt;FONT face="courier new,courier"&gt;distinct_count&lt;/FONT&gt; function to count unique values of a field.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats dc(Username_column) as countUsername by clientip_column&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jul 2022 15:02:20 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2022-07-28T15:02:20Z</dc:date>
    <item>
      <title>How to count a field by another one and removes duplicates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-field-by-another-one-and-removes-duplicates/m-p/607386#M211166</link>
      <description>&lt;P&gt;Hello everyone !&lt;BR /&gt;&lt;BR /&gt;After a few hours of research i come ask your help.&lt;/P&gt;
&lt;P&gt;Here is my data :&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;Username_column&lt;/TD&gt;
&lt;TD width="50%" height="27px"&gt;clientip_column&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="50%" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="50%" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="50%" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="50%" height="27px"&gt;yyy.yyy.yyy.yyy&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username2&lt;/TD&gt;
&lt;TD width="50%" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="27px"&gt;username2&lt;/TD&gt;
&lt;TD height="27px"&gt;zzz.zzz.zzz.zzz&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="27px"&gt;username3&lt;/TD&gt;
&lt;TD height="27px"&gt;yyy.yyy.yyy.yyy&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="27px"&gt;username3&lt;/TD&gt;
&lt;TD height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, what i would like to do is to create another column called "countUsername" which contain the number of usernames by clientip without duplicates (of usernames).&lt;BR /&gt;&lt;BR /&gt;Here is my dream table (what i want) :&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;Username_column&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;clientip_column&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;countUsername&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;yyy.yyy.yyy.yyy&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username2&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username2&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;zzz.zzz.zzz.zzz&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="10px"&gt;username3&lt;/TD&gt;
&lt;TD width="25%" height="10px"&gt;yyy.yyy.yyy.yyy&lt;/TD&gt;
&lt;TD width="25%" height="10px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="50%" height="27px"&gt;username3&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="25%" height="27px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried various of things like :&lt;/P&gt;
&lt;PRE&gt;| eventstats values(count(Username_column)) as countUsername by clientip_column&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;creating a multivalue column and trying of mvdedup().&lt;/P&gt;
&lt;P&gt;combine my Username_column and my clientip_column like so :&lt;/P&gt;
&lt;PRE&gt;| eval countUsername=Username_column. " " . clientip_column&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;and doing lots of things on that, if(mach)), regex, ...&lt;/P&gt;
&lt;P&gt;But everything that i tried didn't work. The best thing that i can get is :&lt;/P&gt;
&lt;PRE&gt;| eventstats count(Username_column) as countUsername by clientip_column&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;But with this line, my usernames are duplicated. (like the table bellow, i tried some things with this result but no results on my side)&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="254.2px" height="27px"&gt;Username_column&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;clientip_column&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;countUsername&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="254.2px" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="254.2px" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="254.2px" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="254.2px" height="27px"&gt;username1&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;yyy.yyy.yyy.yyy&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="254.2px" height="27px"&gt;username2&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="254.2px" height="27px"&gt;username2&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;zzz.zzz.zzz.zzz&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="254.2px" height="25px"&gt;username3&lt;/TD&gt;
&lt;TD width="127.1px" height="25px"&gt;yyy.yyy.yyy.yyy&lt;/TD&gt;
&lt;TD width="127.1px" height="25px"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="254.2px" height="27px"&gt;username3&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;xxx.xxx.xxx.xxx&lt;/TD&gt;
&lt;TD width="127.1px" height="27px"&gt;5&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you are wondering why i'm using &lt;STRONG&gt;eventstats&lt;/STRONG&gt; instead of &lt;STRONG&gt;stats&lt;/STRONG&gt;. The reason is that before this line, i have a large search with multiple stats commands, and if i don't use eventstats, all my others columns at the end of my large request won't show up.&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:20:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-field-by-another-one-and-removes-duplicates/m-p/607386#M211166</guid>
      <dc:creator>ERFFFFF</dc:creator>
      <dc:date>2022-07-28T15:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count a field by another one and removes duplicates</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-field-by-another-one-and-removes-duplicates/m-p/607389#M211167</link>
      <description>&lt;P&gt;Just add this to your current search&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats dc(Username_column) as countUsername by clientip_column&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:00:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-field-by-another-one-and-removes-duplicates/m-p/607389#M211167</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2022-07-28T15:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: Count a field by another one and removes duplicates</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-field-by-another-one-and-removes-duplicates/m-p/607390#M211168</link>
      <description>&lt;P&gt;You were so very close.&amp;nbsp; Use the &lt;FONT face="courier new,courier"&gt;distinct_count&lt;/FONT&gt; function to count unique values of a field.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats dc(Username_column) as countUsername by clientip_column&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:02:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-field-by-another-one-and-removes-duplicates/m-p/607390#M211168</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2022-07-28T15:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: Count a field by another one and removes duplicates</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-field-by-another-one-and-removes-duplicates/m-p/607506#M211224</link>
      <description>&lt;P&gt;Damm.... indeed close...&lt;BR /&gt;Thank you very much for your help !&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 11:01:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-count-a-field-by-another-one-and-removes-duplicates/m-p/607506#M211224</guid>
      <dc:creator>ERFFFFF</dc:creator>
      <dc:date>2022-07-29T11:01:50Z</dc:date>
    </item>
  </channel>
</rss>

