<?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 the output of chart command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500514#M139342</link>
    <description>&lt;P&gt;Thanks @woodcock , These is awesome. These sorts the Chart by Date desc, I want to add the Duration also to sort chart as desc order of duration. Is that possible ?&lt;/P&gt;</description>
    <pubDate>Wed, 04 Dec 2019 17:14:55 GMT</pubDate>
    <dc:creator>dpatiladobe</dc:creator>
    <dc:date>2019-12-04T17:14:55Z</dc:date>
    <item>
      <title>Sort the output of chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500512#M139340</link>
      <description>&lt;P&gt;I am trying to plot chart by ObjectName , Date by Duration. And wanted to sort them by Date desc and Duration desc. I am not able to get same.&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;some search .....| eval ObjectName=if(isnull(ObjectName), "Full_Processing_time",ObjectName) |eval Date=strftime(_time,"%d/%m/%y") | eval Duration=round(tonumber(Duration)/1000/60,2)  | chart  max(Duration)  as D by   ObjectName,Date | sort 0 D Date | fields - D Date&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Dec 2019 17:28:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500512#M139340</guid>
      <dc:creator>dpatiladobe</dc:creator>
      <dc:date>2019-12-03T17:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sort the output of chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500513#M139341</link>
      <description>&lt;P&gt;First of all, you cannot sort by &lt;CODE&gt;D&lt;/CODE&gt; because this is involved in a 2-dimensional matrix; you can only sort by the &lt;CODE&gt;X-axis&lt;/CODE&gt; ( &lt;CODE&gt;Date&lt;/CODE&gt; ) or &lt;CODE&gt;Y-axis&lt;/CODE&gt; ( &lt;CODE&gt;ObjectName&lt;/CODE&gt; ) field names (or both).  In this case, you would like the the date sorting reversed so that the most recent is on the left instead of the right.&lt;BR /&gt;
I have done this many times several different ways but I have decided to try something new this time.&lt;BR /&gt;
Try adding this to the bottom of your existing search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| fields ObjectName * [| makeresults 
| addinfo
| foreach info_*_time [ bin &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; span=1d | eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=strftime(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "%m/%d/%Y") ]
| map search="|gentimes start=$info_min_time$ end=$info_max_time$"
| sort 0 - starttime
| fields starttime
| eval starttime = strftime(starttime, "%m/%d/%Y")
| stats list(starttime) AS search
| nomv search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Here is a run-anywhere example (try running for &lt;CODE&gt;Last 7 Days&lt;/CODE&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats range(_time) AS Duration WHERE index="_*" AND sourcetype="*splunk*" BY sourcetype _time span=1d
| rename sourcetype AS ObjectName

| rename COMMENT AS "Everything above generates sample data; everything below is your solution."

| eval ObjectName=if(isnull(ObjectName), "Full_Processing_time",ObjectName) 
| eval Duration=round(tonumber(Duration)/1000/60,2)
| eval Date=strftime(_time, "%m/%d/%Y")
| chart limit=0 max(Duration) AS D BY ObjectName Date
| fields ObjectName * [| makeresults 
| addinfo
| foreach info_*_time [ bin &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; span=1d | eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=strftime(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "%m/%d/%Y") ]
| map search="|gentimes start=$info_min_time$ end=$info_max_time$"
| sort 0 - starttime
| fields starttime
| eval starttime = strftime(starttime, "%m/%d/%Y")
| stats list(starttime) AS search
| nomv search]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 07:03:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500513#M139341</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-04T07:03:18Z</dc:date>
    </item>
    <item>
      <title>Re: Sort the output of chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500514#M139342</link>
      <description>&lt;P&gt;Thanks @woodcock , These is awesome. These sorts the Chart by Date desc, I want to add the Duration also to sort chart as desc order of duration. Is that possible ?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 17:14:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500514#M139342</guid>
      <dc:creator>dpatiladobe</dc:creator>
      <dc:date>2019-12-04T17:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sort the output of chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500515#M139343</link>
      <description>&lt;P&gt;If i add | sort -D after the fields ObjectName * , it sorts according to Duration desc but then it goes and sort Date as asc&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats range(_time) AS Duration WHERE index="_*" AND sourcetype="*splunk*" BY sourcetype _time span=1d
 | rename sourcetype AS ObjectName

 | rename COMMENT AS "Everything above generates sample data; everything below is your solution."

 | eval ObjectName=if(isnull(ObjectName), "Full_Processing_time",ObjectName) 
 | eval Duration=round(tonumber(Duration)/1000/60,2)
 | eval Date=strftime(_time, "%m/%d/%Y")
 | chart limit=0 max(Duration) AS D BY ObjectName Date
 | fields ObjectName * [| makeresults 
 | addinfo
 | foreach info_*_time [ bin &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; span=1d | eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=strftime(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "%m/%d/%Y") ]
 | map search="|gentimes start=$info_min_time$ end=$info_max_time$"
 | sort 0 - starttime
 | fields starttime
 | eval starttime = strftime(starttime, "%m/%d/%Y")
 | stats list(starttime) AS search
 | nomv search]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 17:44:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500515#M139343</guid>
      <dc:creator>dpatiladobe</dc:creator>
      <dc:date>2019-12-04T17:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sort the output of chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500516#M139344</link>
      <description>&lt;P&gt;Never use &lt;CODE&gt;| sort&lt;/CODE&gt; without a number.  EVER.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 18:06:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500516#M139344</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-04T18:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: Sort the output of chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500517#M139345</link>
      <description>&lt;P&gt;No, sorting by &lt;CODE&gt;D&lt;/CODE&gt; is not possible and I mentioned this in the very first part of my answer,  That field's data is now 2-dimensional and sorting in 2 dimensions has no meaning.  Take a look at the output and think about it and you will see what I mean.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 18:09:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500517#M139345</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-04T18:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sort the output of chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500518#M139346</link>
      <description>&lt;P&gt;Thanks I got it&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 18:38:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-the-output-of-chart-command/m-p/500518#M139346</guid>
      <dc:creator>dpatiladobe</dc:creator>
      <dc:date>2019-12-04T18:38:54Z</dc:date>
    </item>
  </channel>
</rss>

