<?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 Enrich event with number of business days till end of the month in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241974#M188934</link>
    <description>&lt;P&gt;I would like to include an evaluated field to the events returned in the search containing the number of business days between the timestamp of the event and the end of the event month. I have a subsear returning the number of business days untill the end of the month:&lt;/P&gt;

&lt;P&gt;eval TtoEOM=[search * Earliest=$eventtime$ latest=+1month@month | timechart count by host span=1d | appendpipe [|stats count |addinfo | eval temp=info_min_time."##".info_max_time | makemv temp delim="##" | mvexpand temp | eval count=0 | eval _time=temp | table _time count] | timechart span=1d sum(count) as count | fillnull | eval dayname = strftime(_time, "%a") | eval target = strftime(_time, "%d%m%y") |search dayname!=Sat dayname!=Sun | stats count as ret | return $ret]&lt;/P&gt;

&lt;P&gt;However, I'm unble to get the event time into the Earliest parameter of the subsearch.&lt;BR /&gt;
Thank you!&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 07:57:03 GMT</pubDate>
    <dc:creator>SP987541</dc:creator>
    <dc:date>2020-09-29T07:57:03Z</dc:date>
    <item>
      <title>Enrich event with number of business days till end of the month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241974#M188934</link>
      <description>&lt;P&gt;I would like to include an evaluated field to the events returned in the search containing the number of business days between the timestamp of the event and the end of the event month. I have a subsear returning the number of business days untill the end of the month:&lt;/P&gt;

&lt;P&gt;eval TtoEOM=[search * Earliest=$eventtime$ latest=+1month@month | timechart count by host span=1d | appendpipe [|stats count |addinfo | eval temp=info_min_time."##".info_max_time | makemv temp delim="##" | mvexpand temp | eval count=0 | eval _time=temp | table _time count] | timechart span=1d sum(count) as count | fillnull | eval dayname = strftime(_time, "%a") | eval target = strftime(_time, "%d%m%y") |search dayname!=Sat dayname!=Sun | stats count as ret | return $ret]&lt;/P&gt;

&lt;P&gt;However, I'm unble to get the event time into the Earliest parameter of the subsearch.&lt;BR /&gt;
Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:57:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241974#M188934</guid>
      <dc:creator>SP987541</dc:creator>
      <dc:date>2020-09-29T07:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Enrich event with number of business days till end of the month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241975#M188935</link>
      <description>&lt;P&gt;Neat search!&lt;/P&gt;

&lt;P&gt;I noticed that you are having trouble with &lt;CODE&gt;earliest&lt;/CODE&gt;, and also notice you've spelled it in your example &lt;STRONG&gt;Earliest&lt;/STRONG&gt;.  Try changing it to all lower case.  Without that change TtoEOM (in my testing) is some massive number, but when I change it TtoEOM returns a very reasonable number.&lt;/P&gt;

&lt;P&gt;Like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval TtoEOM=[search * earliest=$eventtime$ latest=+1month@month | timechart count by host span=1d | appendpipe [|stats count |addinfo | eval temp=info_min_time."##".info_max_time | makemv temp delim="##" | mvexpand temp | eval count=0 | eval _time=temp | table _time count] | timechart span=1d sum(count) as count | fillnull | eval dayname = strftime(_time, "%a") | eval target = strftime(_time, "%d%m%y") |search dayname!=Sat dayname!=Sun | stats count as ret | return $ret]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Nov 2015 03:06:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241975#M188935</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2015-11-22T03:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Enrich event with number of business days till end of the month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241976#M188936</link>
      <description>&lt;P&gt;I spent quite a bit of time on this and cannot figure out a good way to do it.  I did, however, figure out a better way to do the math:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval WorkdaysUntilEndOfCurrentMonth = [|gentimes
[|noop | stats count AS start | eval start=strftime(now(),                             "%m/%d/%Y")
   | return start=start]
[|noop | stats count AS end   | eval   end=strftime(relative_time(now(), "+1mon@mon"), "%m/%d/%Y")
   | return     end=end]
| search starthuman!="Sat*" AND starthuman!="Sun*" | stats count as WorkdaysUntilEndOfCurrentMonth
   | return $WorkdaysUntilEndOfCurrentMonth]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Nov 2015 17:45:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241976#M188936</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-11-23T17:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Enrich event with number of business days till end of the month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241977#M188937</link>
      <description>&lt;P&gt;Show us a run-anywhere example of this actually working end-to-end.  I don't see how you can pass outer search fields to a subsearch without using &lt;CODE&gt;map&lt;/CODE&gt; which defeats the whole purpose.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2015 17:51:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241977#M188937</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-11-23T17:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Enrich event with number of business days till end of the month</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241978#M188938</link>
      <description>&lt;P&gt;Thank you for your valuable inputs! Based on those inputs I've been looking around some more and found this query that does provide me with the result (i.e. enrich my events with an attribute counting the number of business days between event date and the end of the month):&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;| transaction IDT | eval start=relative_time(_time,"+1d@d")| eval end=relative_time(_time,"+1month@month") | eval Date=mvrange(start,end,86400) | convert ctime(Date) timeformat="%+"| eval NoOfBusinessDays=mvcount(mvfilter(NOT match(Date,"(Sun|Sat).*"))) | fields NoOfBusinessDays&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:59:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Enrich-event-with-number-of-business-days-till-end-of-the-month/m-p/241978#M188938</guid>
      <dc:creator>SP987541</dc:creator>
      <dc:date>2020-09-29T07:59:38Z</dc:date>
    </item>
  </channel>
</rss>

