<?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: Order Column Headers in reverse alphabetical order after chart command in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Order-Column-Headers-in-reverse-alphabetical-order-after-chart/m-p/256465#M76785</link>
    <description>&lt;P&gt;It's a work around where an sorting index will be added to the column names (quarters). Try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval qtr=floor((tonumber(strftime(_time,"%m"))-1)/3)+1 | eval qtr=tostring(5-qtr).strftime(_time," %Y")."-Q".(qtr)
| chart dc(userDay) as userDays, dc(userID) as distinctUsers over groupName by qtr
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;BR /&gt;
Since you column names can be generated from the selected timerange, give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| eval qtr=floor((tonumber(strftime(_time,"%m"))-1)/3)+1 | eval qtr=strftime(_time," %Y")."-Q".(qtr)
   | chart dc(userDay) as userDays, dc(userID) as distinctUsers over groupName by qtr 
   | table groupName  [| gentimes start=10/1/2010  | search [| gentimes start=-1 | addinfo | where starttime&amp;gt;info_min_time AND starttime&amp;lt;info_max_time| table starttime ] | eval temp=1 | rename starttime as _time | sort - _time  | eval qtr=floor((tonumber(strftime(_time,"%m"))-1)/3)+1 | eval qtr=strftime(_time," %Y")."-Q".(qtr) | dedup qtr | eval qtr="\"*".qtr."\"" | stats list(qtr) as qtr | nomv qtr | rename qtr as search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Explanation: The subsearch after the table command is generating the list of Year-Quarter combination for the selected timed range, sorting it in descending order and returning as string to be used in table command.&lt;/P&gt;</description>
    <pubDate>Mon, 21 Mar 2016 22:15:04 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2016-03-21T22:15:04Z</dc:date>
    <item>
      <title>Order Column Headers in reverse alphabetical order after chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Order-Column-Headers-in-reverse-alphabetical-order-after-chart/m-p/256464#M76784</link>
      <description>&lt;P&gt;I have a search that ends with the following commands:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval qtr=strftime(_time,"%Y")."-Q".(floor((tonumber(strftime(_time,"%m"))-1)/3)+1)
| chart dc(userDay) as userDays, dc(userID) as distinctUsers over groupName by qtr
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I really want to display this data so that the most recent quarter is the leftmost column. In other words:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;distinctUsers: 2015-Q4 | distinctUsers: 2015-Q3 | userDays: 2015-Q4 | userDays: 2015-Q3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Unfortunately, for any given quarter that I run this search, I won't know what the field names are to sort by. So, I can't use a  &lt;CODE&gt;table&lt;/CODE&gt; command. The chart command orders in the opposite direction since it does a default sort alphabetically.&lt;/P&gt;

&lt;P&gt;Thoughts on how I can work around this?&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 21:40:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Order-Column-Headers-in-reverse-alphabetical-order-after-chart/m-p/256464#M76784</guid>
      <dc:creator>bclarke5765</dc:creator>
      <dc:date>2016-03-21T21:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: Order Column Headers in reverse alphabetical order after chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Order-Column-Headers-in-reverse-alphabetical-order-after-chart/m-p/256465#M76785</link>
      <description>&lt;P&gt;It's a work around where an sorting index will be added to the column names (quarters). Try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval qtr=floor((tonumber(strftime(_time,"%m"))-1)/3)+1 | eval qtr=tostring(5-qtr).strftime(_time," %Y")."-Q".(qtr)
| chart dc(userDay) as userDays, dc(userID) as distinctUsers over groupName by qtr
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;BR /&gt;
Since you column names can be generated from the selected timerange, give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...| eval qtr=floor((tonumber(strftime(_time,"%m"))-1)/3)+1 | eval qtr=strftime(_time," %Y")."-Q".(qtr)
   | chart dc(userDay) as userDays, dc(userID) as distinctUsers over groupName by qtr 
   | table groupName  [| gentimes start=10/1/2010  | search [| gentimes start=-1 | addinfo | where starttime&amp;gt;info_min_time AND starttime&amp;lt;info_max_time| table starttime ] | eval temp=1 | rename starttime as _time | sort - _time  | eval qtr=floor((tonumber(strftime(_time,"%m"))-1)/3)+1 | eval qtr=strftime(_time," %Y")."-Q".(qtr) | dedup qtr | eval qtr="\"*".qtr."\"" | stats list(qtr) as qtr | nomv qtr | rename qtr as search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Explanation: The subsearch after the table command is generating the list of Year-Quarter combination for the selected timed range, sorting it in descending order and returning as string to be used in table command.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 22:15:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Order-Column-Headers-in-reverse-alphabetical-order-after-chart/m-p/256465#M76785</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-03-21T22:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: Order Column Headers in reverse alphabetical order after chart command</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Order-Column-Headers-in-reverse-alphabetical-order-after-chart/m-p/256466#M76786</link>
      <description>&lt;P&gt;This works, but when I display more than four quarters I have an issue. It displays 2014-Q4 before 2015-Q3 which I don't want. If I could do this in reverse alphabetical order it would work.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Mar 2016 14:30:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Order-Column-Headers-in-reverse-alphabetical-order-after-chart/m-p/256466#M76786</guid>
      <dc:creator>bclarke5765</dc:creator>
      <dc:date>2016-03-22T14:30:44Z</dc:date>
    </item>
  </channel>
</rss>

