<?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: How can I select the maximum X values in a field based on another field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456771#M129113</link>
    <description>&lt;P&gt;top returns the most common values not the max values.  If you add additional 2:4 to the test data then 2:4 replaces 2:8 in the results.  Thanks though.  The code to create the test table is really useful.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jul 2018 18:04:17 GMT</pubDate>
    <dc:creator>paulkrier</dc:creator>
    <dc:date>2018-07-24T18:04:17Z</dc:date>
    <item>
      <title>How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456764#M129106</link>
      <description>&lt;P&gt;I have a data set that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;X     Y
1     5
1     4
1     3
1     2
1     1
2     10
2      9
2      8
2      4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to select the maximum 3 values in Y for each value of X:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;X     Y
1     5
1     4
1     3
2     10
2     9
2     8
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm looking at sort and top, sort allows me to sort on each field, but the count argument seems to only work on the total number of results returned. Top is looking for the most common values, not the maximum values.  Am I missing something?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;pk&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 16:54:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456764#M129106</guid>
      <dc:creator>paulkrier</dc:creator>
      <dc:date>2018-07-24T16:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456765#M129107</link>
      <description>&lt;PRE&gt; ...| sort X Y | dedup 3 X &lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jul 2018 17:26:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456765#M129107</guid>
      <dc:creator>pradeepkumarg</dc:creator>
      <dc:date>2018-07-24T17:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456766#M129108</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;...| sort X, - Y | dedup 3 X
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jul 2018 17:36:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456766#M129108</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2018-07-24T17:36:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456767#M129109</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw="1:5 1:4 1:3 1:2 1:1 2:10 2:9 2:8 2:4"
| makemv raw
| mvexpand raw
| rename raw AS _raw
| rex "^(?&amp;lt;X&amp;gt;[^:]+):(?&amp;lt;Y&amp;gt;[^:]+)$"
| table X Y

| rename COMMENT "Everything above generates sample event data; everything below is your solution"

| top 3 Y BY X
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jul 2018 17:36:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456767#M129109</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-24T17:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456768#M129110</link>
      <description>&lt;P&gt;Just add &lt;CODE&gt;sort 3 -Y by X&lt;/CODE&gt; to the end of your current search.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 17:51:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456768#M129110</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-07-24T17:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456769#M129111</link>
      <description>&lt;P&gt;sort by is not working, I had tried this actually.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 17:56:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456769#M129111</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2018-07-24T17:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456770#M129112</link>
      <description>&lt;P&gt;I don't think the sort command supports the by keyword.  At least not in 6.5.4 which is what I am on.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:02:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456770#M129112</guid>
      <dc:creator>paulkrier</dc:creator>
      <dc:date>2018-07-24T18:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456771#M129113</link>
      <description>&lt;P&gt;top returns the most common values not the max values.  If you add additional 2:4 to the test data then 2:4 replaces 2:8 in the results.  Thanks though.  The code to create the test table is really useful.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:04:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456771#M129113</guid>
      <dc:creator>paulkrier</dc:creator>
      <dc:date>2018-07-24T18:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456772#M129114</link>
      <description>&lt;P&gt;Brilliant! I didn't know dedup took the number of dups to keep.  Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:09:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456772#M129114</guid>
      <dc:creator>paulkrier</dc:creator>
      <dc:date>2018-07-24T18:09:44Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456773#M129115</link>
      <description>&lt;P&gt;yes you are right.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:14:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456773#M129115</guid>
      <dc:creator>thambisetty</dc:creator>
      <dc:date>2018-07-24T18:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: How can I select the maximum X values in a field based on another field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456774#M129116</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval raw="1:5 1:4 1:3 1:2 1:1 2:10 2:9 2:8 2:4"
| makemv raw
| mvexpand raw
| rename raw AS _raw
| rex "^(?&amp;lt;X&amp;gt;[^:]+):(?&amp;lt;Y&amp;gt;[^:]+)$"
| table X Y

| rename COMMENT "Everything above generates sample event data; everything below is your solution"

| stats values(Y) AS Y BY X
| eval Y=mvindex(Y, -3, mvcount(Y))
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:17:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-select-the-maximum-X-values-in-a-field-based-on/m-p/456774#M129116</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2018-07-24T18:17:32Z</dc:date>
    </item>
  </channel>
</rss>

