<?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 year month string in timechart legend in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149127#M41669</link>
    <description>&lt;P&gt;This does show legend for my sample view (appears in ascending order of time and values comes as this.&lt;BR /&gt;
2014-10&lt;BR /&gt;
2014-11&lt;BR /&gt;
2014-12&lt;BR /&gt;
2015-01&lt;BR /&gt;
2015-02&lt;BR /&gt;
2015-03&lt;BR /&gt;
2015-04&lt;BR /&gt;
2015-05&lt;/P&gt;</description>
    <pubDate>Fri, 18 Jul 2014 19:57:32 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2014-07-18T19:57:32Z</dc:date>
    <item>
      <title>Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149123#M41665</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to sort the legend in my timechart chronologically but can't seem to make it work.&lt;/P&gt;

&lt;P&gt;This is my search:&lt;/P&gt;

&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;
  &lt;CODE&gt;&lt;BR /&gt;
index=batch&lt;BR /&gt;
| rex field=partName "regular(?&amp;lt;tmpPartName&amp;gt;.*)"&lt;BR /&gt;
| rex field=tmpPartName "(?&amp;lt;partNameMonth&amp;gt;[a-zA-Z]+)[0-9]+"&lt;BR /&gt;
| rex field=tmpPartName "[a-zA-Z]+(?&amp;lt;partNameYear&amp;gt;[0-9]+)"&lt;BR /&gt;
| eval newPartName = partNameYear + " " + partNameMonth&lt;BR /&gt;
| timechart span=1d limit=15 sum(duration) by newPartName&lt;BR /&gt;
  &lt;/CODE&gt;&lt;BR /&gt;
&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Sample values for the field partName:&lt;/P&gt;

&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;
  &lt;CODE&gt;&lt;BR /&gt;
regularjan15&lt;BR /&gt;
regularmar15&lt;BR /&gt;
regularapr15&lt;BR /&gt;
regularmay15&lt;BR /&gt;
regularfeb15&lt;BR /&gt;
regularnov14&lt;BR /&gt;
regularoct14&lt;BR /&gt;
regulardec14&lt;BR /&gt;
&lt;/CODE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;Anyone have an idea how I can do this ?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2014 16:05:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149123#M41665</guid>
      <dc:creator>splunkmasterfle</dc:creator>
      <dc:date>2014-07-18T16:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149124#M41666</link>
      <description>&lt;P&gt;I would do this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=batch
| rex field=partName "regular(?&amp;lt;tmpDate&amp;gt;.*)"
| eval newPartName = strftime(strptime(tmpDate,"%b%y"),"%Y-%m")
| timechart span=1d limit=15 sum(duration) by newPartName
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Jul 2014 17:28:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149124#M41666</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-07-18T17:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149125#M41667</link>
      <description>&lt;P&gt;strptime(tmpDate,"%b%y") will return NULL as it requires a day part as well. It should be changed with strptime("01-".tmpDate,"%d-%b%y"), keeping remaining things same.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2014 17:49:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149125#M41667</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-07-18T17:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149126#M41668</link>
      <description>&lt;P&gt;This "works" but doesn't sort the values in the legend of my timechart, which is what I was asking&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2014 18:18:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149126#M41668</guid>
      <dc:creator>splunkmasterfle</dc:creator>
      <dc:date>2014-07-18T18:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149127#M41669</link>
      <description>&lt;P&gt;This does show legend for my sample view (appears in ascending order of time and values comes as this.&lt;BR /&gt;
2014-10&lt;BR /&gt;
2014-11&lt;BR /&gt;
2014-12&lt;BR /&gt;
2015-01&lt;BR /&gt;
2015-02&lt;BR /&gt;
2015-03&lt;BR /&gt;
2015-04&lt;BR /&gt;
2015-05&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2014 19:57:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149127#M41669</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-07-18T19:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149128#M41670</link>
      <description>&lt;P&gt;This is my search now&lt;/P&gt;

&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
  index=batch&lt;BR /&gt;
| eval hours = (duration/(1000*60*60))&lt;BR /&gt;
| rex field=partName "regular(?&lt;TMPDATE&gt;.*)"&lt;BR /&gt;
| eval newPartTime = strftime(strptime(tmpDate + "01","%b%y%d"),"%Y-%b")&lt;BR /&gt;
| timechart span=1d limit=15 sum(duration) by newPartTime&lt;BR /&gt;
&lt;/TMPDATE&gt;&lt;/CODE&gt;&lt;BR /&gt;
&lt;/SPAN&gt;&lt;/P&gt;

&lt;P&gt;The legend is sorted alphabetically:&lt;BR /&gt;
&lt;SPAN&gt;&lt;BR /&gt;
&lt;CODE&gt;&lt;BR /&gt;
2014 - Apr&lt;BR /&gt;
2014 - Aug&lt;BR /&gt;
2014 - Dec&lt;BR /&gt;
2014 - Jul&lt;BR /&gt;
2014 - Jun&lt;BR /&gt;
2014 - May&lt;BR /&gt;
2014 - Nov&lt;BR /&gt;
2014 - Oct&lt;BR /&gt;
2014 - Sep&lt;BR /&gt;
2015 - Apr&lt;BR /&gt;
2015 - Fed&lt;BR /&gt;
[...]&lt;BR /&gt;
&lt;/CODE&gt;&lt;BR /&gt;
&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:07:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149128#M41670</guid>
      <dc:creator>splunkmasterfle</dc:creator>
      <dc:date>2020-09-28T17:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149129#M41671</link>
      <description>&lt;P&gt;Yes, Splunk automatically sorts by the "by" clause of the &lt;CODE&gt;timechart&lt;/CODE&gt; command. Since &lt;CODE&gt;newPartName&lt;/CODE&gt; is a string, I would expect it to sort exactly as it did.&lt;/P&gt;

&lt;P&gt;That's why I set the format to &lt;CODE&gt;"%Y-%m"&lt;/CODE&gt; instead of &lt;CODE&gt;"%Y-%b"&lt;/CODE&gt; - because then it would sort by month number instead of month name.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jul 2014 23:08:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149129#M41671</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-07-18T23:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149130#M41672</link>
      <description>&lt;P&gt;It's true that changing the month to a digit will fix the issue. Thank you for the suggestion but my question is how do I sort the legend with the format %Y-%b.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jul 2014 15:21:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149130#M41672</guid>
      <dc:creator>splunkmasterfle</dc:creator>
      <dc:date>2014-07-21T15:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149131#M41673</link>
      <description>&lt;P&gt;You can't. Splunk sorts the legend based on the value of newPartName.&lt;BR /&gt;
If it is in the format %Y-%b, then the months are going to sort alphabetically.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jul 2014 16:33:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149131#M41673</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2014-07-21T16:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149132#M41674</link>
      <description>&lt;P&gt;If its acceptable to you, you can go with format like this "%Y - %m (%b)". This will get sorted properly and it does shows the string format month as well.&lt;/P&gt;

&lt;P&gt;2014 - 04(Apr) &lt;BR /&gt;
2014 - 08(Aug)&lt;BR /&gt;
2014 - 12(Dec)&lt;BR /&gt;
2014 - 07(Jul)&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jul 2014 17:11:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149132#M41674</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2014-07-21T17:11:15Z</dc:date>
    </item>
    <item>
      <title>Re: Sort year month string in timechart legend</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149133#M41675</link>
      <description>&lt;P&gt;This is what I ended up doing. Thank you for all the help!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jul 2014 15:16:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Sort-year-month-string-in-timechart-legend/m-p/149133#M41675</guid>
      <dc:creator>splunkmasterfle</dc:creator>
      <dc:date>2014-07-23T15:16:38Z</dc:date>
    </item>
  </channel>
</rss>

