<?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 How to sort dynamic column names after timechart and transpose in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-dynamic-column-names-after-timechart-and-transpose/m-p/508202#M142015</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm creating a report with the following search that runs each month covering the past 3 months of data.&lt;/P&gt;&lt;P&gt;It works and I can display the results in a bar chart but it gets sorted alphabetically by sourcetype.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=* | timechart span=1mon count by sourcetype 
 | eval _time = strftime(_time,"%B")
 | rename _time as Time
 | fields - _*
 | transpose header_field=Time column_name="sourcetype"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to sort it by count of last month. So for example if I run the report in July I get columns "sourcetype", "April", "May", "June". Each month that I run the report the column names will change. I can get the results I want this month&amp;nbsp; by adding:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; | sort - "June"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I set this up automatically&amp;nbsp; so that the results are sorted by the last column (previous month)?&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jul 2020 23:14:16 GMT</pubDate>
    <dc:creator>gnoriega</dc:creator>
    <dc:date>2020-07-08T23:14:16Z</dc:date>
    <item>
      <title>How to sort dynamic column names after timechart and transpose</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-dynamic-column-names-after-timechart-and-transpose/m-p/508202#M142015</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm creating a report with the following search that runs each month covering the past 3 months of data.&lt;/P&gt;&lt;P&gt;It works and I can display the results in a bar chart but it gets sorted alphabetically by sourcetype.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=* | timechart span=1mon count by sourcetype 
 | eval _time = strftime(_time,"%B")
 | rename _time as Time
 | fields - _*
 | transpose header_field=Time column_name="sourcetype"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to sort it by count of last month. So for example if I run the report in July I get columns "sourcetype", "April", "May", "June". Each month that I run the report the column names will change. I can get the results I want this month&amp;nbsp; by adding:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; | sort - "June"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I set this up automatically&amp;nbsp; so that the results are sorted by the last column (previous month)?&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jul 2020 23:14:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-dynamic-column-names-after-timechart-and-transpose/m-p/508202#M142015</guid>
      <dc:creator>gnoriega</dc:creator>
      <dc:date>2020-07-08T23:14:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort dynamic column names after timechart and transpose</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-dynamic-column-names-after-timechart-and-transpose/m-p/508207#M142017</link>
      <description>&lt;P&gt;This works by giving the previous month a fixed field name and then sorting by that before naming it correctly at the end&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=*
| timechart span=1mon count by sourcetype 
| eval _time = if(_time=relative_time(now(),"-1mon@mon"), "Last Month", strftime(_time,"%B")) 
| rename _time as Time 
| fields - _* 
| transpose header_field=Time column_name="sourcetype"
| sort - "Last Month"
| eval name=strftime(relative_time(now(),"-1mon@mon"),"%B")
| eval {name}='Last Month'
| fields - "Last Month" name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;which is simply just calling the relative -1 month from now as last month rather than the name itself and then fixing up the name after the sort.&lt;/P&gt;&lt;P&gt;"Last Month" could be anything temporary&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2020 00:10:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-dynamic-column-names-after-timechart-and-transpose/m-p/508207#M142017</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2020-07-09T00:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to sort dynamic column names after timechart and transpose</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-sort-dynamic-column-names-after-timechart-and-transpose/m-p/508324#M142037</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp; this is precisely what I needed.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jul 2020 15:07:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-sort-dynamic-column-names-after-timechart-and-transpose/m-p/508324#M142037</guid>
      <dc:creator>gnoriega</dc:creator>
      <dc:date>2020-07-09T15:07:35Z</dc:date>
    </item>
  </channel>
</rss>

