<?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: chart sorting by last field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19090#M2868</link>
    <description>&lt;P&gt;I think I see the problem. You need to instantiate a value for the field "today":&lt;/P&gt;

&lt;P&gt;| eval today=round(time()) &lt;/P&gt;

&lt;P&gt;-- Your search might work with this:&lt;/P&gt;

&lt;P&gt;index=reporter &lt;BR /&gt;
| dedup TKT_NUMBER &lt;BR /&gt;
| eval time=strptime(LASTOCCURRENCE, "%b %d %Y %I:%M%p") &lt;BR /&gt;
| bucket time span=1d &lt;BR /&gt;
| eval today=round(time()) &lt;BR /&gt;
| eval time=if(round((today-time)/60/60/24)=0,"Today",time) &lt;BR /&gt;
| eval time=if(time="Today",time,strftime(time, "%b %d")) &lt;BR /&gt;
| chart count by NOTIFY_GROUP, time &lt;BR /&gt;
| rename NOTIFY_GROUP AS Group&lt;BR /&gt;
| sort - Today&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 14:28:44 GMT</pubDate>
    <dc:creator>Gilberto_Castil</dc:creator>
    <dc:date>2020-09-28T14:28:44Z</dc:date>
    <item>
      <title>chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19083#M2861</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;We have the following chart which displays current ticket counts over the last 7 days for different groups but need to be able to sort on the count for the last day. In this case we would need to sort on Jul 30 but it would need to be dynamic and always sort on the most recent date in the chart. Here is the search we have:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=reporter | dedup TKT_NUMBER | eval time=strptime(LASTOCCURRENCE, "%b %d %Y %I:%M%p") | bucket time span=1d | convert timeformat="%b %d" ctime("time") | chart count by NOTIFY_GROUP, time | rename NOTIFY_GROUP AS Group
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is this possible?&lt;BR /&gt;
 &lt;IMG src="http://splunk-base.splunk.com//storage/2013-07-30_1146.png" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2013 15:50:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19083#M2861</guid>
      <dc:creator>aaronkorn</dc:creator>
      <dc:date>2013-07-30T15:50:57Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19084#M2862</link>
      <description>&lt;P&gt;This is tricky because of the dynamic nature of your field. Here is one easy way to change this but there is a beautification aspect to note. Notice how you've lost the precision on your field names as those have now become part of the table itself. &lt;/P&gt;

&lt;P&gt;Assuming that you consistently have ten (10) rows in your table and seven (7) columns, this will create the desired effect:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transpose 10 | transpose 10 | fields - column | sort - "row 7"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will change the format of your original table, like the one above, to something like this:&lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/Untitled803.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;The other side effect is that by using the &lt;STRONG&gt;&lt;CODE&gt;transpose&lt;/CODE&gt;&lt;/STRONG&gt; command you've lost the ability to drill down. &lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;[07-31-2130] Update:&lt;/P&gt;

&lt;P&gt;While thinking about this, it occurred to me that renaming the last field is simple as long as it is understood that the dynamic "time" variable that you have is actually a list. &lt;/P&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/Untitled803.2.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;P&gt;The key here is to perform a comparison between the value of the "time" list and the "today" list. If the comparison fits, then we should assign the value of the latest ("today") variable to the appropriate value in the "time" list.&lt;/P&gt;

&lt;P&gt;The comparison I used was all using the ephoc date. It is just easier for me to deal with numeric values, rather than strings&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval time=if(round((today-time)/60/60/24)=0,"Today",time)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then we convert to the string desired:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval time=if(time="Today",time,strftime(time, "%b %d"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/Untitled803.3.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;And, finally, you can apply the chart transformation and sort:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| chart count over NOTIFY_GROUP by time 
| rename NOTIFY_GROUP AS Group
| sort - Today
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/Untitled803-2.png" alt="alt text" /&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;This will not change your format and it will keep click precision.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2013 16:37:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19084#M2862</guid>
      <dc:creator>Gilberto_Castil</dc:creator>
      <dc:date>2013-07-30T16:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19085#M2863</link>
      <description>&lt;P&gt;Thanks for the response. Couldnt we do something like this?&lt;/P&gt;

&lt;P&gt;index=reporter | dedup TKT_NUMBER | eval time=strptime(LASTOCCURRENCE, "%b %d %Y %I:%M%p") | bucket time span=1d | eval today=time() | convert timeformat="%b %d" ctime("time") ctime("today") | chart count by NOTIFY_GROUP, time | rename NOTIFY_GROUP AS Group | sort - "today"&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:28:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19085#M2863</guid>
      <dc:creator>aaronkorn</dc:creator>
      <dc:date>2020-09-28T14:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19086#M2864</link>
      <description>&lt;P&gt;I did some testing with this and found a solution. They key is compare the dynamic "time" variable to the "today" variable. &lt;/P&gt;

&lt;P&gt;time=if((today-time)&amp;lt;24hours,"Today",time)&lt;/P&gt;

&lt;P&gt;That will assign the value of "Today" to the dynamic "time" variable and then you can perform the sort by the "Today" column. I was challenged with the string comparisons so defaulted using pure epoch times for the comparison and it worked.&lt;/P&gt;

&lt;P&gt;| eval time=if(round((today-time)/60/60/24)=0,"Today",time)&lt;/P&gt;

&lt;P&gt;--&lt;/P&gt;

&lt;P&gt;I will post more if needed.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2013 13:50:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19086#M2864</guid>
      <dc:creator>Gilberto_Castil</dc:creator>
      <dc:date>2013-07-31T13:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19087#M2865</link>
      <description>&lt;P&gt;Thanks for the detailed explanation! I tried adding it to my previous search but it still doesn't appear to be working. I wonder since LASTOCCURRENCE isnt epoch that why its throwing it off...&lt;/P&gt;

&lt;P&gt;index=reporter | dedup TKT_NUMBER | eval time=strptime(LASTOCCURRENCE, "%b %d %Y %I:%M%p") | bucket time span=1d | eval time=if(round((today-time)/60/60/24)=0,"Today",time) | eval time=if(time="Today",time,strftime(time, "%b %d")) | chart count by NOTIFY_GROUP, time | rename NOTIFY_GROUP AS Group&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:28:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19087#M2865</guid>
      <dc:creator>aaronkorn</dc:creator>
      <dc:date>2020-09-28T14:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19088#M2866</link>
      <description>&lt;P&gt;Correct. If LASTOCCURRENCE is not epoch, the calculation suggested does not work. What is the original format for LASTOCCURRENCE?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2013 17:46:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19088#M2866</guid>
      <dc:creator>Gilberto_Castil</dc:creator>
      <dc:date>2013-07-31T17:46:08Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19089#M2867</link>
      <description>&lt;P&gt;Its in the following format: Jul 31 2013  1:49PM&lt;/P&gt;

&lt;P&gt;Is there a way we can convert to epoch then eval on that?&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2013 17:53:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19089#M2867</guid>
      <dc:creator>aaronkorn</dc:creator>
      <dc:date>2013-07-31T17:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19090#M2868</link>
      <description>&lt;P&gt;I think I see the problem. You need to instantiate a value for the field "today":&lt;/P&gt;

&lt;P&gt;| eval today=round(time()) &lt;/P&gt;

&lt;P&gt;-- Your search might work with this:&lt;/P&gt;

&lt;P&gt;index=reporter &lt;BR /&gt;
| dedup TKT_NUMBER &lt;BR /&gt;
| eval time=strptime(LASTOCCURRENCE, "%b %d %Y %I:%M%p") &lt;BR /&gt;
| bucket time span=1d &lt;BR /&gt;
| eval today=round(time()) &lt;BR /&gt;
| eval time=if(round((today-time)/60/60/24)=0,"Today",time) &lt;BR /&gt;
| eval time=if(time="Today",time,strftime(time, "%b %d")) &lt;BR /&gt;
| chart count by NOTIFY_GROUP, time &lt;BR /&gt;
| rename NOTIFY_GROUP AS Group&lt;BR /&gt;
| sort - Today&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 14:28:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19090#M2868</guid>
      <dc:creator>Gilberto_Castil</dc:creator>
      <dc:date>2020-09-28T14:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19091#M2869</link>
      <description>&lt;P&gt;Still didnt seem to do it. I think adding the new eval helped but the issue is probably still with the LASOCCURRENCE not being epoch&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2013 18:39:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19091#M2869</guid>
      <dc:creator>aaronkorn</dc:creator>
      <dc:date>2013-07-31T18:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19092#M2870</link>
      <description>&lt;P&gt;Also, now the dates are in alphabetical order. Anyway to get around that? Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2013 12:36:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19092#M2870</guid>
      <dc:creator>aaronkorn</dc:creator>
      <dc:date>2013-08-01T12:36:24Z</dc:date>
    </item>
    <item>
      <title>Re: chart sorting by last field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19093#M2871</link>
      <description>&lt;P&gt;I tried sending an email but it came back undeliverable&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2013 14:09:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/chart-sorting-by-last-field/m-p/19093#M2871</guid>
      <dc:creator>aaronkorn</dc:creator>
      <dc:date>2013-08-05T14:09:00Z</dc:date>
    </item>
  </channel>
</rss>

