<?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: sort based on 2 values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/sort-based-on-2-values/m-p/256052#M76668</link>
    <description>&lt;P&gt;How about this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; my search
| stats sum(Quantity) as Quantity by ID,IssueType,Severity,Manager
| sort +Manager -Quantity
| streamstats global=f count as rank by Manager
| WHERE rank &amp;lt;= 5
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 27 Jan 2017 15:13:19 GMT</pubDate>
    <dc:creator>rjthibod</dc:creator>
    <dc:date>2017-01-27T15:13:19Z</dc:date>
    <item>
      <title>sort based on 2 values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sort-based-on-2-values/m-p/256051#M76667</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
I'm new to Splunk and I'm struggling to find a solution for the requirement I have.&lt;/P&gt;

&lt;P&gt;Here is my requirement:&lt;BR /&gt;
I have  an Index where I get ID, IssueType, Severity, Quantity and another lookup table where I have ID, Manager, Sr Manager, Director.&lt;BR /&gt;
So, I'm joining the index with lookup table on ID and doing the following query to get the Quantity for each Manager/Sr Manager/Director.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;my search|Stats sum(Quantity) by ID,IssueType,Severity,Manager| sort -Quantity.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;By doing this I'm getting the result for all Managers sorted in descending order. But I need to only get 5 highest values of Quantity for EACH manager.&lt;BR /&gt;
Here is an example of result what I'm getting.&lt;/P&gt;

&lt;P&gt;ID Manager Quantity&lt;BR /&gt;
1 ABC             150&lt;BR /&gt;
2 BDC             140&lt;BR /&gt;
3 ABC              130&lt;BR /&gt;
4 XYZ               120&lt;BR /&gt;
5 ABC              110&lt;BR /&gt;
6 BDC              100&lt;BR /&gt;
7 XYZ               90&lt;/P&gt;

&lt;P&gt;But, I want the result in following format.&lt;/P&gt;

&lt;P&gt;ID Manager Quantity&lt;BR /&gt;
1 ABC             150&lt;BR /&gt;
2 ABC              130&lt;BR /&gt;
3 ABC              110&lt;BR /&gt;
4 BDC              140&lt;BR /&gt;
5 BDC               110&lt;BR /&gt;
6 XYZ             120&lt;BR /&gt;
7 XYZ               90&lt;/P&gt;

&lt;P&gt;Please let me know if we could do it.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 14:50:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sort-based-on-2-values/m-p/256051#M76667</guid>
      <dc:creator>snam</dc:creator>
      <dc:date>2017-01-27T14:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: sort based on 2 values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sort-based-on-2-values/m-p/256052#M76668</link>
      <description>&lt;P&gt;How about this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; my search
| stats sum(Quantity) as Quantity by ID,IssueType,Severity,Manager
| sort +Manager -Quantity
| streamstats global=f count as rank by Manager
| WHERE rank &amp;lt;= 5
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Jan 2017 15:13:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sort-based-on-2-values/m-p/256052#M76668</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-01-27T15:13:19Z</dc:date>
    </item>
    <item>
      <title>Re: sort based on 2 values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/sort-based-on-2-values/m-p/256053#M76669</link>
      <description>&lt;P&gt;you saved my day..Thanks a lot for quick response&lt;/P&gt;</description>
      <pubDate>Fri, 27 Jan 2017 16:30:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/sort-based-on-2-values/m-p/256053#M76669</guid>
      <dc:creator>snam</dc:creator>
      <dc:date>2017-01-27T16:30:09Z</dc:date>
    </item>
  </channel>
</rss>

