<?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: Need to change the span based on hour of day in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/746994#M241740</link>
    <description>&lt;P&gt;thanks for the update&lt;/P&gt;</description>
    <pubDate>Tue, 27 May 2025 16:40:10 GMT</pubDate>
    <dc:creator>wjrbrady</dc:creator>
    <dc:date>2025-05-27T16:40:10Z</dc:date>
    <item>
      <title>Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/746980#M241738</link>
      <description>&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;I am trying to change in the search itself to change the span in timechart.&amp;nbsp; So if the hour is say greater than 7 and less than 19 make the span=10m&amp;nbsp; else 1hr&lt;/P&gt;&lt;P&gt;example&lt;/P&gt;&lt;P&gt;| eval hour=strftime(_time,"%H")&lt;BR /&gt;| eval span=if(hour&amp;gt;=7 AND hour&amp;lt;19,"10m","1h")&lt;BR /&gt;|timechart span=span count(field1) ,count(field2) by field3&lt;/P&gt;</description>
      <pubDate>Tue, 27 May 2025 10:56:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/746980#M241738</guid>
      <dc:creator>wjrbrady</dc:creator>
      <dc:date>2025-05-27T10:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/746983#M241739</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/147385"&gt;@wjrbrady&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I'm sorry but it isn't possible to dinamically change the span value in a timechart command.&lt;/P&gt;&lt;P&gt;You have to define a value.&lt;/P&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Tue, 27 May 2025 13:26:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/746983#M241739</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2025-05-27T13:26:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/746994#M241740</link>
      <description>&lt;P&gt;thanks for the update&lt;/P&gt;</description>
      <pubDate>Tue, 27 May 2025 16:40:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/746994#M241740</guid>
      <dc:creator>wjrbrady</dc:creator>
      <dc:date>2025-05-27T16:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747032#M241744</link>
      <description>&lt;P&gt;How would results of such search look? Do you want to change the span for the whole search or have multiple spans within one search? (what sense would it make then???)&lt;/P&gt;</description>
      <pubDate>Tue, 27 May 2025 19:41:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747032#M241744</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-05-27T19:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747054#M241746</link>
      <description>&lt;P&gt;&lt;U&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/147385"&gt;@wjrbrady&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Splunk timechart command’s span argument must be a fixed value per search execution—you cannot dynamically change the span within a single timechart based on the hour of the day.&lt;/P&gt;&lt;P&gt;However, you can achieve similar logic using a combination of eval, bin, and append&lt;/P&gt;&lt;P&gt;Eg: using append&lt;BR /&gt;(&lt;BR /&gt;search ... earliest=@d latest=now&lt;BR /&gt;| eval hour=strftime(_time,"%H")&lt;BR /&gt;| where hour &amp;gt; 7 AND hour &amp;lt; 19&lt;BR /&gt;| timechart span=10m sum(count) as count&lt;BR /&gt;)&lt;BR /&gt;| append&lt;BR /&gt;(&lt;BR /&gt;search ... earliest=@d latest=now&lt;BR /&gt;| eval hour=strftime(_time,"%H")&lt;BR /&gt;| where hour &amp;lt;= 7 OR hour &amp;gt;= 19&lt;BR /&gt;| timechart span=1h sum(count) as count&lt;BR /&gt;)&lt;BR /&gt;| sort _time&lt;/P&gt;&lt;P&gt;Also if you want a single timeline but with custom buckets, you can create your own time buckets using eval and bin&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Prewin&lt;BR /&gt;Splunk Enthusiast | Always happy to help! If this answer helped you, please consider marking it as the solution or giving a kudos. Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 04:37:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747054#M241746</guid>
      <dc:creator>PrewinThomas</dc:creator>
      <dc:date>2025-05-28T04:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747057#M241747</link>
      <description>&lt;P&gt;You can technically achieve this through post processing of the timechart data. All you do is create your timechart in the smaller span, then add up the 6 X 10 minute blocks outside your time range and remove the unnecessary ones.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example using streamstats/eventstats - there are probably other ways, but this works&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_audit
| timechart span=10m count
| eval t=strftime(_time, "%H")
| streamstats window=6 sum(eval(if(t&amp;gt;=7 AND t&amp;lt;19, null(), count))) as hourly by t
| eventstats max(hourly) as hourly_max min(hourly) as hourly_min by t
| where hourly=hourly_min OR isnull(hourly)
| eval hourly=hourly_max
| fields - hourly* t&lt;/LI-CODE&gt;&lt;P&gt;You could make it simpler depending on your total search time range.&lt;/P&gt;&lt;P&gt;You will see the X axis will not change, but you will only have hourly data points in the 19-07 hours.&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 04:59:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747057#M241747</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-05-28T04:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747073#M241748</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/6367"&gt;@bowesmana&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/28010"&gt;@PrewinThomas&lt;/a&gt;&amp;nbsp;give you two different approaches. &amp;nbsp;I will put a different spin on Prewin27's append method. (BTW, there should be no need to sort by _time after timechart.) &amp;nbsp;To avoid searching the same data multiple times, I use &lt;A href="https://help.splunk.com/en/splunk-enterprise/search/spl-search-reference/latest/search-commands/map" target="_blank" rel="noopener"&gt;map&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;In the following example, I simplify interval split by restricting total search window to &lt;A href="mailto:-1d@d" target="_blank"&gt;-1d@d&lt;/A&gt;&amp;nbsp;- &lt;A href="mailto:-0d@d" target="_blank"&gt;-0d@d&lt;/A&gt;.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| tstats count where index=_internal earliest=-1d@d latest=-0d@d
| addinfo ``` just to extract boundaries ```
| eval point1 = relative_time(info_min_time, "+7h"), point2 = relative_time(info_min_time, "+17h")
| eval interval = mvappend(json_object("earliest", info_min_time, "latest", point1),
  json_object("earliest", point1, "latest", point2),
  json_object("earliest", point2, "latest", info_max_time))
| mvexpand interval
| spath input=interval
| eval span = if(earliest == point1, "10m", "1h")
``` the above uses prior knowledge about point1 and point2 ```
| map search="search index=_internal earliest=$earliest$ latest=$latest$
  | timechart span=$span$ count"&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-05-27 at 11.17.48 PM.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/39208i1F5FD0D591E33158/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2025-05-27 at 11.17.48 PM.png" alt="Screenshot 2025-05-27 at 11.17.48 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Obviously if your search window is not one 24-hour period, interval split becomes more complex. &amp;nbsp;But the same logic can apply to any window.&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 06:23:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747073#M241748</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2025-05-28T06:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747095#M241752</link>
      <description>&lt;P&gt;Be aware though that not all aggregation functions are further aggregatable.&lt;/P&gt;&lt;P&gt;For example - sum or max/min can be aggregated from smaller spans into a correct overall value but avg cannot.&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 07:33:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747095#M241752</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-05-28T07:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747241#M241783</link>
      <description>&lt;P&gt;bit nerdy here, but&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;if you know in advance what you want to do and can figure out the maths, then you can do others, e.g. post aggregation of average is simply sum/count&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_audit
| eval r=random() % 100
| timechart span=10m avg(r) as avg_r sum(r) as s_r count
| eval h=strftime(_time, "%H"), d=strftime(_time, "%d"), m=strftime(_time, "%M")
| eventstats sum(count) as count_1_hour sum(s_r) as sum_r_1_hour by d h
| where (h&amp;gt;=7 AND h&amp;lt;19 OR m=0)
| eval avg_r = if(h&amp;lt;7 OR h&amp;gt;=19, sum_r_1_hour / count_1_hour, avg_r)
| fields - d h m sum_r_1_hour count_1_hour s_r&lt;/LI-CODE&gt;&lt;P&gt;percentiles on the other hand are a little more complicated. I suspect using the sitimechart function will do a lot of the work for the first pass and then it's a bit of post_processing of the&amp;nbsp;psrsvd_rd* variables. I'm not totally sure how the si_* values are aggregated for percentiles, I did play around with it some years ago and got lost in the weeds, but it was a somewhat interesting exercise&lt;/P&gt;</description>
      <pubDate>Fri, 30 May 2025 01:27:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747241#M241783</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2025-05-30T01:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747250#M241786</link>
      <description>&lt;P&gt;Of course. I know it, you know it... But people tend to forget it. Way too many times I've seen average speed or average fuel consumption calculated by averaging multiple averages.&lt;/P&gt;</description>
      <pubDate>Fri, 30 May 2025 05:20:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747250#M241786</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2025-05-30T05:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747259#M241788</link>
      <description>&lt;P&gt;Hello picklerick,&lt;/P&gt;&lt;P&gt;I was trying to do a compare to today and last week but based on volume of data in the over night i wanted the data in an hour bucket and during the day wanted 10minute buckes.&amp;nbsp; This would be for an alert where you cant use tokens based on time to set the span.&amp;nbsp; So it would be for the whole search&lt;/P&gt;</description>
      <pubDate>Fri, 30 May 2025 10:19:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747259#M241788</guid>
      <dc:creator>wjrbrady</dc:creator>
      <dc:date>2025-05-30T10:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747260#M241789</link>
      <description>&lt;P&gt;thank you for the eg i will take a look.&amp;nbsp; also i tried to do the eval bin but it would not let me do an if or case statement to set the bin size.&amp;nbsp; Do you have an example&lt;/P&gt;</description>
      <pubDate>Fri, 30 May 2025 10:22:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/747260#M241789</guid>
      <dc:creator>wjrbrady</dc:creator>
      <dc:date>2025-05-30T10:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change the span based on hour of day</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/750618#M242386</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/147385"&gt;@wjrbrady&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;good for you, see next time!&lt;/P&gt;&lt;P&gt;Ciao and happy splunking&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;&lt;P&gt;P.S.: Karma Points are appreciated by all the contributors &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jul 2025 06:50:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Need-to-change-the-span-based-on-hour-of-day/m-p/750618#M242386</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2025-07-29T06:50:45Z</dc:date>
    </item>
  </channel>
</rss>

