<?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 to get TOP 3 values from STATS list() in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484484#M193435</link>
    <description>&lt;P&gt;@rajatsinghbagga &lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | sort  -elapseJobTime
 | stats  list(JOBNAME) as JOBNAME list(JOBID) as JOBID list(elapseJobTime) as elapseJobTime  by desc
 | eval JOBNAME=mvrange(JOBNAME,0,2) ,JOBID=mvrange(JOBID,0,2) elapseJobTime=mvrange(elapseJobTime,0,2)  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 20 Sep 2019 11:06:25 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2019-09-20T11:06:25Z</dc:date>
    <item>
      <title>How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484483#M193434</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;

&lt;P&gt;I am trying to get the top 3 max values of a field "elapseJobTime" for all the instances associated with the field "desc".  &lt;/P&gt;

&lt;P&gt;In order to achieve this, I first sorted the field "elapseJobTime"  in descending order and then executed the STATS command to list out the values of all the respective fields I was looking for.  I am getting the output in the sequence as expected but the only issue is that my search lists down 100's of values for the fields JOBNAME  JOBID elapseJobTime but I want to restrict my output to just top 3 values. I tried to use HEAD 3 after the STATS but no luck. &lt;/P&gt;

&lt;P&gt;Please assist.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| sort  -elapseJobTime
| stats  list(JOBNAME) as JOBNAME list(JOBID) as JOBID list(elapseJobTime) as elapseJobTime  by desc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output should be like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;desc               JOBNAME     JOBID         elapseJobTime  
desc1             JOB1              J1                 .31
                  JOB1              J2                 .27
                  JOB3              J3                 .27
desc2             JOB4              J4                 .71
                  JOB5              J5                 .11
                  JOB5              J6                 .10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you&lt;BR /&gt;
Rajat&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 10:37:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484483#M193434</guid>
      <dc:creator>rajatsinghbagga</dc:creator>
      <dc:date>2019-09-20T10:37:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484484#M193435</link>
      <description>&lt;P&gt;@rajatsinghbagga &lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | sort  -elapseJobTime
 | stats  list(JOBNAME) as JOBNAME list(JOBID) as JOBID list(elapseJobTime) as elapseJobTime  by desc
 | eval JOBNAME=mvrange(JOBNAME,0,2) ,JOBID=mvrange(JOBID,0,2) elapseJobTime=mvrange(elapseJobTime,0,2)  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Sep 2019 11:06:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484484#M193435</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-09-20T11:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484485#M193436</link>
      <description>&lt;P&gt;Thanks @kamlesh_vaghela , Just tried it now. I am only getting the "desc" values and rest of the fields are coming blank.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 11:22:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484485#M193436</guid>
      <dc:creator>rajatsinghbagga</dc:creator>
      <dc:date>2019-09-20T11:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484486#M193437</link>
      <description>&lt;P&gt;@rajatsinghbagga&lt;/P&gt;

&lt;P&gt;Can you please share OP from below search?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| sort -elapseJobTime 
| stats list(JOBNAME) as JOBNAME list(JOBID) as JOBID list(elapseJobTime) as elapseJobTime by desc 
| eval tJOBNAME=typeof(JOBNAME),tJOBID=typeof(JOBID),telapseJobTime=typeof(elapseJobTime)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is it possible to share a screenshot of your search result?? &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| sort -elapseJobTime 
| stats list(JOBNAME) as JOBNAME list(JOBID) as JOBID list(elapseJobTime) as elapseJobTime by desc 
| eval JOBNAME1=mvrange(JOBNAME,0,2) ,JOBID1=mvrange(JOBID,0,2) elapseJobTime1=mvrange(elapseJobTime,0,2) 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Sep 2019 11:38:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484486#M193437</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-09-20T11:38:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484487#M193438</link>
      <description>&lt;P&gt;The output is coming as below along with the list of all the values in the fields  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;tJOBID  tJOBNAME    telapseJobTime
Multivalue  Multivalue  Multivalue
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;From the previous query with mvrange the output was &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;desc     JOBID  JOBNAME elapseJobTime
desc1
desc2
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Sep 2019 11:49:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484487#M193438</guid>
      <dc:creator>rajatsinghbagga</dc:creator>
      <dc:date>2019-09-20T11:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484488#M193439</link>
      <description>&lt;P&gt;@rajatsinghbagga&lt;/P&gt;

&lt;P&gt;You can use 'mvindex` to get a subset of the multivalue fields. Please check doc for more information.&lt;/P&gt;

&lt;P&gt;Can you please try this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| sort -elapseJobTime 
 | stats list(JOBNAME) as JOBNAME list(JOBID) as JOBID list(elapseJobTime) as elapseJobTime by desc
| eval JOBNAME=mvindex(JOBNAME,0,2), JOBID=mvindex(JOBID,0,2), elapseJobTime=mvindex(elapseJobTime,0,2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/SearchReference/MultivalueEvalFunctions#mvindex.28MVFIELD.2CSTARTINDEX.2C_ENDINDEX.29"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/SearchReference/MultivalueEvalFunctions#mvindex.28MVFIELD.2CSTARTINDEX.2C_ENDINDEX.29&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 12:13:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484488#M193439</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-09-20T12:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484489#M193440</link>
      <description>&lt;P&gt;The answer is simple and tricky at the same time.&lt;/P&gt;

&lt;P&gt;You just need to add &lt;CODE&gt;limit=3&lt;/CODE&gt; after stats.&lt;/P&gt;

&lt;P&gt;It seem's simple, but limit doesn't get highlighted as you might be used to. And limit is not mentioned in &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/SearchReference/Stats"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/SearchReference/Stats&lt;/A&gt; .&lt;/P&gt;

&lt;P&gt;This is what you need in more detail:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| sort  -elapseJobTime&lt;BR /&gt;
| stats limit=3 list(JOBNAME) as JOBNAME list(JOBID) as JOBID list(elapseJobTime) as elapseJobTime  by desc&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 13:26:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484489#M193440</guid>
      <dc:creator>dpeukert</dc:creator>
      <dc:date>2019-09-20T13:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484490#M193441</link>
      <description>&lt;P&gt;Hello @dpeukert &lt;BR /&gt;
This didn't worked.  I am getting "Error in 'stats' command: The argument 'limit=3' is invalid." &lt;BR /&gt;
Thanks Rajat&lt;/P&gt;</description>
      <pubDate>Sun, 22 Sep 2019 23:43:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484490#M193441</guid>
      <dc:creator>rajatsinghbagga</dc:creator>
      <dc:date>2019-09-22T23:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484491#M193442</link>
      <description>&lt;P&gt;This worked - Perfect !!    Thank you Rajat&lt;/P&gt;</description>
      <pubDate>Sun, 22 Sep 2019 23:47:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484491#M193442</guid>
      <dc:creator>rajatsinghbagga</dc:creator>
      <dc:date>2019-09-22T23:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484492#M193443</link>
      <description>&lt;P&gt;@rajatsinghbagga Glad to help you. Can you please accept the answer to close this question?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 06:29:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484492#M193443</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-09-23T06:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484493#M193444</link>
      <description>&lt;P&gt;Thanks @kamlesh_vaghela i accepted the answer. However I noticed that I am not able to apply color codes on the output, I can see the option in the column to format based on the colour codes but when I apply it does nothing. Is there a way I can color the cells of "elapseJobTime" column based on the high and low values appearing in this column... I was able to do it with the normal table values but it seem getting these values in the list format is causing this issue.. Anything if you can suggest that will be great.. Thanks Rajat &lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 07:39:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484493#M193444</guid>
      <dc:creator>rajatsinghbagga</dc:creator>
      <dc:date>2019-09-23T07:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484494#M193445</link>
      <description>&lt;P&gt;@rajatsinghbagga&lt;BR /&gt;
Please check below link for table column colour formating.  If it's still not helpful then post a new question with  &lt;CODE&gt;table&lt;/CODE&gt; tag from your dashboard. This practice will help other peoples to search for this kind of issue. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/Viz/TableFormatsFormatting"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/Viz/TableFormatsFormatting&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/7.3.1/Viz/TableFormatsXML#Table_format_source_code_example"&gt;https://docs.splunk.com/Documentation/Splunk/7.3.1/Viz/TableFormatsXML#Table_format_source_code_example&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2019 08:56:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/484494#M193445</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2019-09-23T08:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to get TOP 3 values from STATS list()</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/682742#M233242</link>
      <description>&lt;P&gt;If you didn't want multiple lines. This is how I would accomplish the same thing.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| sort -elapseJobTime 
 | stats list(eval(myindex(JOBNAME,0,2))) as JOBNAME list(eval(mvindex(JOBID,0,2))) as JOBID list(eval(myindex(elapseJobTime,0,2))) as elapseJobTime by desc&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 13:23:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-TOP-3-values-from-STATS-list/m-p/682742#M233242</guid>
      <dc:creator>Yepeza</dc:creator>
      <dc:date>2024-04-02T13:23:24Z</dc:date>
    </item>
  </channel>
</rss>

