<?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 On Field With Multiple Values in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50081#M12029</link>
    <description>&lt;P&gt;Most eval functions balk with multi-value fields. I'm skipping over strptime in these examples, but know that you need a single value field for strptime.&lt;/P&gt;

&lt;P&gt;If you just need to work with the first or last values, you can put them into new fields before working with them.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval start_date_first=mvindex(start_date, 0)
| eval start_date_last=mvindex(start_date, -1)
| eval end_date_first=mvindex(end_date, 0)
| eval end_date_last=mvindex(end_date, -1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Another option is to create a separate row for each users start and end date:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval periods=mvzip(start_date, end_date)  // create multi-value field for with pairs of comma separated dates
| mvexpand periods                          // separate each pair into separate events
| makemv periods delim=","                  // separate the pair into a multi-value
| eval start_date=mvindex(periods, 0)       // set the first value to start_date
| eval end_date=mvindex(periods, -1)        // set the last value to end_date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've broken this down a little granularly than necessary. Many of these could be combined, but remember you often need to cast mvindex() output into a type with tostring() or tonumber(). For intance:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval foo= mvindex(bar, 0) * 2             // always throws error
| eval foo= tonumber(mvindex(bar, 0)) * 2   // works
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 04 Jun 2015 18:10:02 GMT</pubDate>
    <dc:creator>mrobichaud_splu</dc:creator>
    <dc:date>2015-06-04T18:10:02Z</dc:date>
    <item>
      <title>Eval On Field With Multiple Values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50074#M12022</link>
      <description>&lt;P&gt;I'm trying to get the time difference of two dates on a table but when my user has multiple values for the end_date and start_dates my time_diff is not calculated. See below:&lt;/P&gt;

&lt;P&gt;User         end_date                    start_date                           time_diff&lt;BR /&gt;
User1       2011-11-04T13:17Z   2011-11-04 09:18:20      14320&lt;BR /&gt;
User2       2011-11-04T21:08Z   2011-11-04 14:08:28&lt;BR /&gt;
                2011-11-04T15:16Z   2011-11-04 16:38:16&lt;BR /&gt;
User3       2011-11-04T15:15Z   2011-11-04 10:18:12&lt;BR /&gt;
                2011-11-04T21:25Z   2011-11-04 14:26:40&lt;BR /&gt;
                2011-11-04T13:35Z   2011-11-04 09:36:45&lt;BR /&gt;
User4       2011-11-04T20:01Z   2011-11-04 16:03:02      13889&lt;/P&gt;

&lt;P&gt;Search:&lt;/P&gt;

&lt;P&gt;source="/Users/user/unit_pretest_.json" | lookup UserSessionsLookup user_id as userId | rename username as "User Name" | eval itime=strptime(start_date,"%Y-%m-%d %H:%M:%S") | eval ptime=strptime(end_date,"%Y-%m-%d %H:%M:%S") | eval TimeDiff=ptime-itime  | table "User Name", start_date, end_date, TimeDiff&lt;/P&gt;

&lt;P&gt;Anyone knows what's wrong here?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:53:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50074#M12022</guid>
      <dc:creator>jr_arzuaga</dc:creator>
      <dc:date>2020-09-28T12:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Eval On Field With Multiple Values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50075#M12023</link>
      <description>&lt;P&gt;Can You try this out with stats command. I am not sure.. Just try it out. It may work !&lt;/P&gt;

&lt;P&gt;stats eval(ptime-itime) AS TimeDiff by "User Name"&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2012 09:25:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50075#M12023</guid>
      <dc:creator>aneeshkjm123</dc:creator>
      <dc:date>2012-11-30T09:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Eval On Field With Multiple Values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50076#M12024</link>
      <description>&lt;P&gt;Not working. It won't allow me to do eval(ptime-itime). It seems like what I need to do is compute the difference and then group by the "User Name" but the syntax above doesn't work. Any thoughts?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2012 14:41:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50076#M12024</guid>
      <dc:creator>jr_arzuaga</dc:creator>
      <dc:date>2012-11-30T14:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Eval On Field With Multiple Values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50077#M12025</link>
      <description>&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;This is the new search I'm trying:&lt;/P&gt;

&lt;P&gt;source="/Users/user/unit_pretest_.json" lookup UserSessionsLookup user_id as userId | rename username as "User Name" | eval itime=strptime(start_date,"%Y-%m-%d %H:%M:%S") | eval ptime=strptime(end_date,"%Y-%m-%d %H:%M:%S") | eval TimeDiff=ptime-itime | stats sum(TimeDiff) as Diff by "User Name" | table "User Name", start_date, end_date, Diff&lt;/P&gt;

&lt;P&gt;I get the same thing, data for users with only one row of sessions data (e.g. User1 and User4 above)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:53:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50077#M12025</guid>
      <dc:creator>jr_arzuaga</dc:creator>
      <dc:date>2020-09-28T12:53:35Z</dc:date>
    </item>
    <item>
      <title>Re: Eval On Field With Multiple Values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50078#M12026</link>
      <description>&lt;P&gt;UPDATE:&lt;/P&gt;

&lt;P&gt;This doesn't work either&lt;/P&gt;

&lt;P&gt;source="/Users/user/unit_pretest_.json" | lookup UserSessionsLookup user_id as userId | rename username as "User Name" | stats sum(strptime(end_date,"%Y-%m-%d %H:%M:%S")-strptime(start_date,"%Y-%m-%d %H:%M:%S")) as TimeDiff by "User Name" | table "User Name", TimeDiff&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:53:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50078#M12026</guid>
      <dc:creator>jr_arzuaga</dc:creator>
      <dc:date>2020-09-28T12:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Eval On Field With Multiple Values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50079#M12027</link>
      <description>&lt;P&gt;what do the raw events look like?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Nov 2012 22:04:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50079#M12027</guid>
      <dc:creator>kristian_kolb</dc:creator>
      <dc:date>2012-11-30T22:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: Eval On Field With Multiple Values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50080#M12028</link>
      <description>&lt;P&gt;Is there any answer for this questions ?&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2013 20:35:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50080#M12028</guid>
      <dc:creator>luthfi49</dc:creator>
      <dc:date>2013-09-21T20:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: Eval On Field With Multiple Values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50081#M12029</link>
      <description>&lt;P&gt;Most eval functions balk with multi-value fields. I'm skipping over strptime in these examples, but know that you need a single value field for strptime.&lt;/P&gt;

&lt;P&gt;If you just need to work with the first or last values, you can put them into new fields before working with them.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval start_date_first=mvindex(start_date, 0)
| eval start_date_last=mvindex(start_date, -1)
| eval end_date_first=mvindex(end_date, 0)
| eval end_date_last=mvindex(end_date, -1)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Another option is to create a separate row for each users start and end date:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval periods=mvzip(start_date, end_date)  // create multi-value field for with pairs of comma separated dates
| mvexpand periods                          // separate each pair into separate events
| makemv periods delim=","                  // separate the pair into a multi-value
| eval start_date=mvindex(periods, 0)       // set the first value to start_date
| eval end_date=mvindex(periods, -1)        // set the last value to end_date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've broken this down a little granularly than necessary. Many of these could be combined, but remember you often need to cast mvindex() output into a type with tostring() or tonumber(). For intance:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval foo= mvindex(bar, 0) * 2             // always throws error
| eval foo= tonumber(mvindex(bar, 0)) * 2   // works
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 04 Jun 2015 18:10:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-On-Field-With-Multiple-Values/m-p/50081#M12029</guid>
      <dc:creator>mrobichaud_splu</dc:creator>
      <dc:date>2015-06-04T18:10:02Z</dc:date>
    </item>
  </channel>
</rss>

