<?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: Using Stats List to get multiple UserIDs into a single field by IP. Need to sort by UserID in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370457#M165173</link>
    <description>&lt;P&gt;Thanks for pointing me in a direction for research. I got an answer that is working for me above but I'm going to take your advice and see how well that does. &lt;/P&gt;</description>
    <pubDate>Tue, 14 Nov 2017 22:32:45 GMT</pubDate>
    <dc:creator>GenericSplunkUs</dc:creator>
    <dc:date>2017-11-14T22:32:45Z</dc:date>
    <item>
      <title>Using Stats List to get multiple UserIDs into a single field by IP. Need to sort by UserID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370452#M165168</link>
      <description>&lt;P&gt;Might have trouble explaining this in an understandable way, might be why I was unable to google my answer. &lt;/P&gt;

&lt;P&gt;I'm using | stats list(userID) by IP | on a search for UserID logins. I get the results of the IP and what UserIDs have logged into it. I need to sort this list I have now by the list(UserID) field with the most UserIDs in it.&lt;/P&gt;

&lt;P&gt;Since these values are getting put into a single field list(userID) i'm not sure I can sort them by count like I want to. &lt;/P&gt;

&lt;P&gt;Any advice? I eventually want to set an alert when an IP has more than a certain number of Users logging into it. But I'm just trying to get this search into my dashboard first. &lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 22:05:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370452#M165168</guid>
      <dc:creator>GenericSplunkUs</dc:creator>
      <dc:date>2017-11-14T22:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats List to get multiple UserIDs into a single field by IP. Need to sort by UserID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370453#M165169</link>
      <description>&lt;P&gt;FYI, list() will list the users in the same order as the events, including duplicates.  If you want a "list" of unique users, use values().  &lt;/P&gt;

&lt;P&gt;To answer the question, you'll just want to get a count of the users in stats as well and then you can sort by that. &lt;/P&gt;

&lt;P&gt;So with the way you have it&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...  | stats list(userID) as users count by IP | sort 0 - count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR with the way you have it, but using a distinct count &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats list(userID) as users dc(userID) as count by IP | sort 0 - count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;OR with a list of distinct users and a distinct count&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... | stats values(userID) as users dc(userID) as count by IP| sort 0 - count
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Nov 2017 22:19:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370453#M165169</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2017-11-14T22:19:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats List to get multiple UserIDs into a single field by IP. Need to sort by UserID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370454#M165170</link>
      <description>&lt;P&gt;@GenericSplunkUser, you should read about &lt;CODE&gt;statistical and charting functions&lt;/CODE&gt; to understand what could be useful when you are trying to use a transforming command like &lt;CODE&gt;stats&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;list()&lt;/CODE&gt; function will give your all userIDs including the duplicates in the same order as they occurred (i.e. reverse chronological order as per data). However, list() can &lt;CODE&gt;show maximum 100 results&lt;/CODE&gt;. Which implies when your IP has more than 100 times user login (can be coming from same user as it accounts for duplicates as well), it will just display 100. &lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;values()&lt;/CODE&gt; function on the other hand will only show unique userIDs however, the results will be sorted in alphabetical order, since the function sorts and find unique values. This can account for more than 100 users (unique) but not all logins.&lt;/P&gt;

&lt;P&gt;You would need to use &lt;CODE&gt;count()&lt;/CODE&gt; and &lt;CODE&gt;distinct_count()&lt;/CODE&gt; ( also used as abbreviated function &lt;CODE&gt;dc()&lt;/CODE&gt; ) to know total user logins including duplicates and unique respectively. Following is the search you can try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;YourBaseSearch&amp;gt;
 | stats dc(usertID) as distinct_user_count count(usertID) user_count values(userID) as distinct_userIDs by IP
 | sort - user_count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer to documentation of Statistical Functions: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonStatsFunctions#Types_of_statistical_and_charting_functions"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonStatsFunctions#Types_of_statistical_and_charting_functions&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 22:23:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370454#M165170</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-14T22:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats List to get multiple UserIDs into a single field by IP. Need to sort by UserID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370455#M165171</link>
      <description>&lt;P&gt;@maciep, you beat me to it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 22:24:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370455#M165171</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-14T22:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats List to get multiple UserIDs into a single field by IP. Need to sort by UserID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370456#M165172</link>
      <description>&lt;P&gt;index=Events  EventType="Logon"  | dedup userID | stats list(user) by ip&lt;/P&gt;

&lt;P&gt;I dedup the userID before I did the stats command so it would only pull a single UserID. Did I just go about that weird and created my issue? &lt;/P&gt;

&lt;P&gt;I think I just answered my own question here with your first suggestion.&lt;/P&gt;

&lt;P&gt;I did the "Index=Events  EventType="Logon" | dedup userID | | stats list(userID) as users count by IP | sort 0 - count" And this is working as I wanted. Giving unique users per IP with a count I can sort on. &lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 22:30:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370456#M165172</guid>
      <dc:creator>GenericSplunkUs</dc:creator>
      <dc:date>2017-11-14T22:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats List to get multiple UserIDs into a single field by IP. Need to sort by UserID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370457#M165173</link>
      <description>&lt;P&gt;Thanks for pointing me in a direction for research. I got an answer that is working for me above but I'm going to take your advice and see how well that does. &lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 22:32:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370457#M165173</guid>
      <dc:creator>GenericSplunkUs</dc:creator>
      <dc:date>2017-11-14T22:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using Stats List to get multiple UserIDs into a single field by IP. Need to sort by UserID</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370458#M165174</link>
      <description>&lt;P&gt;be careful with dedup.  In your search you'll remove dup ids, but what if one user has logged into multiple IPs?  Only one IP will get that count.&lt;/P&gt;

&lt;P&gt;If you're going to dedup, do it by both:  ... | dedup userID, IP&lt;/P&gt;</description>
      <pubDate>Tue, 14 Nov 2017 22:36:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Stats-List-to-get-multiple-UserIDs-into-a-single-field-by/m-p/370458#M165174</guid>
      <dc:creator>maciep</dc:creator>
      <dc:date>2017-11-14T22:36:36Z</dc:date>
    </item>
  </channel>
</rss>

