<?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: eval last event of 3 date fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383317#M111942</link>
    <description>&lt;P&gt;thank's a lot for the time spent to share your knowledge. If I good understand no need to split the line to create fields already existing, (I 've only put the raw because it's sometimes easier) : DAT_DER_IMAP, DAT_DER_POP, DAT_DER_WEB are the names of the fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| foreach DAT_DER_* [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'="NULL",0,strptime(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "%Y%m%d")) ]
| eval correct_date=strftime(if(first_field &amp;gt;= second_field, if(first_field &amp;gt;= third_field, first_field, if (second_field &amp;gt;= third_field, second_field, third_field)), second_field), "%Y%m%d")
| table login_forgee correct_date datecrea
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;no error, but the "correct_date" column is empty&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 21:19:47 GMT</pubDate>
    <dc:creator>splunkLPN</dc:creator>
    <dc:date>2020-09-29T21:19:47Z</dc:date>
    <item>
      <title>eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383311#M111936</link>
      <description>&lt;P&gt;Hello,&lt;BR /&gt;
3 date fields  (A B C) :&lt;BR /&gt;
in the source file &lt;CODE&gt;|20180830|NULL|20180223&lt;/CODE&gt;&lt;BR /&gt;
How can I compare this 3 dates and extract a new field : LastEvent ? &lt;BR /&gt;
the LastEvent value in this case is &lt;CODE&gt;20180830&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Il suppose &lt;CODE&gt;| fillnull value="0"&lt;/CODE&gt; to begin &lt;BR /&gt;
but for the rest ? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
thank's for your help&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 09:59:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383311#M111936</guid>
      <dc:creator>splunkLPN</dc:creator>
      <dc:date>2018-09-17T09:59:19Z</dc:date>
    </item>
    <item>
      <title>Re: eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383312#M111937</link>
      <description>&lt;P&gt;Hi @splunkLPN,&lt;/P&gt;

&lt;P&gt;You need to use &lt;CODE&gt;split&lt;/CODE&gt; and &lt;CODE&gt;mvindex&lt;/CODE&gt; to achieve that.&lt;/P&gt;

&lt;P&gt;I have created run anywhere search which is extracting correct result.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval date="|20180830|NULL|20180223"
| eval date_expand=split(date,"|")
| eval correct_date=mvindex(date_expand,1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Please give it a try and modify query based on your requirement.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 11:02:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383312#M111937</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-09-17T11:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383313#M111938</link>
      <description>&lt;P&gt;Thank you. I extracted a new field that I called "date".      &lt;CODE&gt;| table date&lt;/CODE&gt; give the good result :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    |20140327|NULL|20140327
    |20080901|NULL|20080901
    |20000412|20000412|20000412
    |20110403|NULL|20110403
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;if I try &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults 
|eval date_expand=split(date,"|") 
|eval correct_date=mvindex(date_expand,1)) | table correct_date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've got "Error in 'eval' command: The expression is malformed."&lt;/P&gt;

&lt;P&gt;in "date_expand,&lt;STRONG&gt;1&lt;/STRONG&gt;", the number one give the jungest date or the first position ? I need to extract the jungest date. &lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 12:29:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383313#M111938</guid>
      <dc:creator>splunkLPN</dc:creator>
      <dc:date>2018-09-17T12:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383314#M111939</link>
      <description>&lt;P&gt;First you need to remove &lt;CODE&gt;|makeresults&lt;/CODE&gt; from your query and you have given extra &lt;CODE&gt;)&lt;/CODE&gt; while creating &lt;CODE&gt;correct_date&lt;/CODE&gt; field, your query will be like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourBaseQuery&amp;gt;
| fields date
|eval date_expand=split(date,"|") 
|eval correct_date=mvindex(date_expand,1) | table correct_date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;CODE&gt;mvindex(date_expand,1)&lt;/CODE&gt; will provide date from first position. Can you please explain "jungest date" ?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 12:38:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383314#M111939</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-09-17T12:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383315#M111940</link>
      <description>&lt;P&gt;Here are  samples and the good answer after :&lt;/P&gt;

&lt;P&gt;|20140327|NULL|20140327 : 20140327&lt;BR /&gt;
|20080901|NULL|20080902 : 20080902&lt;BR /&gt;
|20000415|20000412|20000412 : 20000415&lt;BR /&gt;
|20110402|NULL|20110403 : 20110403&lt;/P&gt;

&lt;P&gt;3 fields A, B, C , how keep the last event ? (or how compare 3 date field ?)&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 12:06:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383315#M111940</guid>
      <dc:creator>splunkLPN</dc:creator>
      <dc:date>2018-09-18T12:06:45Z</dc:date>
    </item>
    <item>
      <title>Re: eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383316#M111941</link>
      <description>&lt;P&gt;Try this one&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourquery&amp;gt;
| fields date
| eval date_expand=split(date,"|")
| eval first_field=mvindex(date_expand,1), second_field=mvindex(date_expand,2), third_field=mvindex(date_expand,3)
| foreach *_field [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'="NULL",0,strptime(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "%Y%m%d")) ]
| eval correct_date=strftime(if(first_field &amp;gt;= second_field, if(first_field &amp;gt;= third_field, first_field, if (second_field &amp;gt;= third_field, second_field, third_field)), second_field), "%Y%m%d")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Sep 2018 13:20:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383316#M111941</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-09-18T13:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383317#M111942</link>
      <description>&lt;P&gt;thank's a lot for the time spent to share your knowledge. If I good understand no need to split the line to create fields already existing, (I 've only put the raw because it's sometimes easier) : DAT_DER_IMAP, DAT_DER_POP, DAT_DER_WEB are the names of the fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| foreach DAT_DER_* [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'="NULL",0,strptime(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, "%Y%m%d")) ]
| eval correct_date=strftime(if(first_field &amp;gt;= second_field, if(first_field &amp;gt;= third_field, first_field, if (second_field &amp;gt;= third_field, second_field, third_field)), second_field), "%Y%m%d")
| table login_forgee correct_date datecrea
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;no error, but the "correct_date" column is empty&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:19:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383317#M111942</guid>
      <dc:creator>splunkLPN</dc:creator>
      <dc:date>2020-09-29T21:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383318#M111943</link>
      <description>&lt;P&gt;While calculating correct date you need to modify first_field, second_field and third field with your actual field name (DAT_DER_IMAP, DAT_DER_POP &amp;amp; DAT_DER_WEB).&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 21:19:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383318#M111943</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2020-09-29T21:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383319#M111944</link>
      <description>&lt;P&gt;oh gosh! sorry &lt;EM&gt;blush&lt;/EM&gt; that's works fine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
how can I give you points ?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 16:22:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383319#M111944</guid>
      <dc:creator>splunkLPN</dc:creator>
      <dc:date>2018-09-18T16:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: eval last event of 3 date fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383320#M111945</link>
      <description>&lt;P&gt;Great it worked, if it really helped you then you can accept/upvote my answer.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 16:33:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/eval-last-event-of-3-date-fields/m-p/383320#M111945</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2018-09-18T16:33:30Z</dc:date>
    </item>
  </channel>
</rss>

