<?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: Is there a way to nest the last event inside the eval statement? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-nest-the-last-event-inside-the-eval-statement/m-p/387297#M112990</link>
    <description>&lt;P&gt;@ErikaE ,&lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;last&lt;/CODE&gt; option should work for you or at least this is what I see.  &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Events&lt;/STRONG&gt;&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5481i60171E72332377AA/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;If you see here, the last sourcetype is kvstore and the component is KVStoreCollectionStats&lt;/P&gt;

&lt;P&gt;Now here is my SPL &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_*|table _time,index,sourcetype,component|sort _time|dedup index,sourcetype,component|stats last(eval(case(sourcetype="http_event_collector_metrics",component))) as component
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which yields me the result " HttpEventCollector " which is not in my last event&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5482i273B572927D1A5FC/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Aug 2018 06:20:59 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2018-08-08T06:20:59Z</dc:date>
    <item>
      <title>Is there a way to nest the last event inside the eval statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-nest-the-last-event-inside-the-eval-statement/m-p/387296#M112989</link>
      <description>&lt;P&gt;I'm attempting to use stats to process some data before further calculations are performed. I have too many events for transaction and would like to "keep" certain data from certain values of foo.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(eval(if('foo'="bar", A, null())) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above expression runs, but returns multiple values if there is more than one foo event with different values of A. Sometimes the values are the same for a certain value of foo, but not always. Each field that gets passed through needs mv handling on the other side to get it back down to just one value. That's not ideal as there are 20+ fields that are needed after this stats command. Based on the context of foo I often know whether I want to keep the first or the last value.&lt;/P&gt;

&lt;P&gt;The expression &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(eval(case('foo'="bar", A))) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Returns only one value, from the first event where the condition in the case statement is met. However, this doesn't work when what I want is the last occurrence of 'foo'="bar" and not the first. &lt;/P&gt;

&lt;P&gt;I've checked the &lt;A href="http://docs.splunk.com/Documentation/Splunk/7.1.2/Search/Usestatswithevalexpressionsandfunctions"&gt;eval+stats&lt;/A&gt; documentation and splunk answers, but I'm having trouble finding an example of dynamic fields that uses first() last() earliest() or latest() instead of a sum or count function. &lt;/P&gt;

&lt;P&gt;Ideally I'd do something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |stats last(eval(if('foo'="bar", A, null())) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which would return the value of A for the last event matching the condition foo="bar". However, if foo="bar" is not the last event then no data is returned.  &lt;/P&gt;

&lt;P&gt;Is there a way to nest the last inside the eval statement? Should I be looking at match() instead? &lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 21:51:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-nest-the-last-event-inside-the-eval-statement/m-p/387296#M112989</guid>
      <dc:creator>ErikaE</dc:creator>
      <dc:date>2018-08-07T21:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to nest the last event inside the eval statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-nest-the-last-event-inside-the-eval-statement/m-p/387297#M112990</link>
      <description>&lt;P&gt;@ErikaE ,&lt;/P&gt;

&lt;P&gt;The &lt;CODE&gt;last&lt;/CODE&gt; option should work for you or at least this is what I see.  &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Events&lt;/STRONG&gt;&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5481i60171E72332377AA/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;If you see here, the last sourcetype is kvstore and the component is KVStoreCollectionStats&lt;/P&gt;

&lt;P&gt;Now here is my SPL &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_*|table _time,index,sourcetype,component|sort _time|dedup index,sourcetype,component|stats last(eval(case(sourcetype="http_event_collector_metrics",component))) as component
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which yields me the result " HttpEventCollector " which is not in my last event&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/5482i273B572927D1A5FC/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 06:20:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-nest-the-last-event-inside-the-eval-statement/m-p/387297#M112990</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2018-08-08T06:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to nest the last event inside the eval statement?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-nest-the-last-event-inside-the-eval-statement/m-p/387298#M112991</link>
      <description>&lt;P&gt;I must have had a typo in my syntax somewhere, I'm now seeing the behavior you'd expect.&lt;/P&gt;

&lt;P&gt;Thanks for taking the time to look and work up the example for me! &lt;/P&gt;</description>
      <pubDate>Wed, 08 Aug 2018 13:52:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Is-there-a-way-to-nest-the-last-event-inside-the-eval-statement/m-p/387298#M112991</guid>
      <dc:creator>ErikaE</dc:creator>
      <dc:date>2018-08-08T13:52:42Z</dc:date>
    </item>
  </channel>
</rss>

