<?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 Cannot sort dynamic column in date format in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Cannot-sort-dynamic-column-in-date-format/m-p/344579#M102053</link>
    <description>&lt;P&gt;Hi,&lt;BR /&gt;
  I tried to summary data in each assignment_group_name by month&lt;BR /&gt;
here is my code: &lt;BR /&gt;
index="snow" sourcetype="snow:incident" assignment_group_name="AM*"&lt;BR /&gt;
|dedup number&lt;BR /&gt;
|chart count over assignment_group_name by incoming_month &lt;BR /&gt;
|addtotals&lt;BR /&gt;
|sort by assignment_group_name, incoming_month&lt;/P&gt;

&lt;P&gt;But &lt;STRONG&gt;I need the column to be arranged by date format by starting from the oldest month to the latest one&lt;/STRONG&gt;.&lt;BR /&gt;
I've tried to convert the incoming_month column by trying&lt;/P&gt;

&lt;P&gt;|eval month = strftime(incoming_month, "%b-%y") &lt;BR /&gt;
but it's not working. Please help.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/191375-capture.png" alt="alt text" /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 13:46:41 GMT</pubDate>
    <dc:creator>urapaveerapan</dc:creator>
    <dc:date>2020-09-29T13:46:41Z</dc:date>
    <item>
      <title>Cannot sort dynamic column in date format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-sort-dynamic-column-in-date-format/m-p/344579#M102053</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
  I tried to summary data in each assignment_group_name by month&lt;BR /&gt;
here is my code: &lt;BR /&gt;
index="snow" sourcetype="snow:incident" assignment_group_name="AM*"&lt;BR /&gt;
|dedup number&lt;BR /&gt;
|chart count over assignment_group_name by incoming_month &lt;BR /&gt;
|addtotals&lt;BR /&gt;
|sort by assignment_group_name, incoming_month&lt;/P&gt;

&lt;P&gt;But &lt;STRONG&gt;I need the column to be arranged by date format by starting from the oldest month to the latest one&lt;/STRONG&gt;.&lt;BR /&gt;
I've tried to convert the incoming_month column by trying&lt;/P&gt;

&lt;P&gt;|eval month = strftime(incoming_month, "%b-%y") &lt;BR /&gt;
but it's not working. Please help.&lt;/P&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/191375-capture.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:46:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-sort-dynamic-column-in-date-format/m-p/344579#M102053</guid>
      <dc:creator>urapaveerapan</dc:creator>
      <dc:date>2020-09-29T13:46:41Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot sort dynamic column in date format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-sort-dynamic-column-in-date-format/m-p/344580#M102054</link>
      <description>&lt;P&gt;Sorting of  columns is always done in some way (alphabetic or ascii or something else) when left to its own devices. So the answer to your question is there is no way to do exactly what you want without adding some extra specificity, or changing the labels.&lt;/P&gt;

&lt;P&gt;The latter option is simple, but you have to use the number version of month, e.g., &lt;CODE&gt;|eval month = strftime(incoming_month, "%m-%y")&lt;/CODE&gt; or  &lt;CODE&gt;|eval month = strftime(incoming_month, "%Y-%m")&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The more specific option is to use the column names with wildcards, like this; however, this will only work for the same calendar year because you put the year at the end of the column name&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| fields assignment_group_name Jan* Feb* Mar* Ap* May* Jun* Jul* Aug* Sep* Oct* Nov* Dec* Total*&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;So, if you want to make Splunk do the work for you, you need to switch to &lt;CODE&gt;|eval month = strftime(incoming_month, "%Y-%m")&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 11:33:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-sort-dynamic-column-in-date-format/m-p/344580#M102054</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-04-21T11:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot sort dynamic column in date format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-sort-dynamic-column-in-date-format/m-p/344581#M102055</link>
      <description>&lt;P&gt;You can either create a lookup table with Month Abbreviations to month in digits like Jan - 01(Jan), Feb -02(Feb) etc or  write a macro to perform series rename as shown below. Once you change Dec-16 to 12-Dec-16 it will show up sorted. You can also set usenull=f to hide null fields and add incoming_month="*" to your base search. (PS: All rename below should be shifted to a macro).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="snow" sourcetype="snow:incident" assignment_group_name="AM*" incoming_month="*" 
|dedup number
|chart count over assignment_group_name by date_mdayincoming_month 
|rename "Jan*" as "01(Jan)*"
|rename "Feb*" as "02(Feb)*"
|rename "Mar*" as "03(Mar*"
|rename "Apr*" as "04(Apr)*"
|rename "May*" as "05(May)*"
|rename "Jun*" as "06(Jun)*"
|rename "Jul*" as "07(Jul)*"
|rename "Aug*" as "08(Aug)*"
|rename "Sep*" as "09(Sep)*"
|rename "Oct*" as "10(Oct)*"
|rename "Nov*" as "11(Nov)*"
|rename "Dec*" as "11(Dec)*"
|addtotals
|sort by assignment_group_name, incoming_month
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Apr 2017 11:38:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-sort-dynamic-column-in-date-format/m-p/344581#M102055</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-04-21T11:38:18Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot sort dynamic column in date format</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-sort-dynamic-column-in-date-format/m-p/344582#M102056</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="snow" sourcetype="snow:incident" assignment_group_name="AM*" incoming_month="*" 
| dedup number
| chart count over assignment_group_name by date_mdayincoming_month 
| rename Jan* AS "           Jan*"
         Feb* AS "          Feb*"
         Mar* AS "         Mar*"
         Apr* AS "        Apr*"
         May* AS "       May*"
         Jun* AS "      Jun*"
         Jul* AS "     Jul*"
         Aug* AS "    Aug*"
         Sep* AS "   Sep*"
         Oct* AS "  Oct*"
         Nov* AS " Nov*"
|addtotals
|sort 0 BY assignment_group_name incoming_month
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note that &lt;CODE&gt;Oct&lt;/CODE&gt; has been renamed with 2 leading spaces and &lt;CODE&gt;Nov&lt;/CODE&gt; with just one (and &lt;CODE&gt;Dec&lt;/CODE&gt; not at all).&lt;BR /&gt;
The whitespace is invisible in the chart but forces the alphabetical order that you desire.  This would make a fine &lt;CODE&gt;macro&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 16:49:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-sort-dynamic-column-in-date-format/m-p/344582#M102056</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-21T16:49:50Z</dc:date>
    </item>
  </channel>
</rss>

