<?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 How to extract three latest  values of a field by field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-three-latest-values-of-a-field-by-field/m-p/498973#M138989</link>
    <description>&lt;P&gt;Hi! I have different events and for every event i have a list of reasons. I want to display only three of the reasons for each event, which are latest by time. I use this code:&lt;BR /&gt;
| stats values(Reason) as Reason, values(_time) AS Time by event &lt;BR /&gt;
| sort Reason by Time &lt;BR /&gt;
| eval Reason=mvindex(Reason,0,2) &lt;BR /&gt;
| table event, Time, Reason&lt;BR /&gt;
This doesn't work. What should   I do to make it work?&lt;/P&gt;</description>
    <pubDate>Mon, 23 Mar 2020 11:15:14 GMT</pubDate>
    <dc:creator>pomazanelvira</dc:creator>
    <dc:date>2020-03-23T11:15:14Z</dc:date>
    <item>
      <title>How to extract three latest  values of a field by field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-three-latest-values-of-a-field-by-field/m-p/498973#M138989</link>
      <description>&lt;P&gt;Hi! I have different events and for every event i have a list of reasons. I want to display only three of the reasons for each event, which are latest by time. I use this code:&lt;BR /&gt;
| stats values(Reason) as Reason, values(_time) AS Time by event &lt;BR /&gt;
| sort Reason by Time &lt;BR /&gt;
| eval Reason=mvindex(Reason,0,2) &lt;BR /&gt;
| table event, Time, Reason&lt;BR /&gt;
This doesn't work. What should   I do to make it work?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 11:15:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-three-latest-values-of-a-field-by-field/m-p/498973#M138989</guid>
      <dc:creator>pomazanelvira</dc:creator>
      <dc:date>2020-03-23T11:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract three latest  values of a field by field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-three-latest-values-of-a-field-by-field/m-p/498974#M138990</link>
      <description>&lt;P&gt;What results do you get?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 13:34:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-three-latest-values-of-a-field-by-field/m-p/498974#M138990</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-03-23T13:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract three latest  values of a field by field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-three-latest-values-of-a-field-by-field/m-p/498975#M138991</link>
      <description>&lt;P&gt;I get a table, but Reasons are not sorted by time. So, i don't get the latest reasons&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 13:36:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-three-latest-values-of-a-field-by-field/m-p/498975#M138991</guid>
      <dc:creator>pomazanelvira</dc:creator>
      <dc:date>2020-03-23T13:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract three latest  values of a field by field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-three-latest-values-of-a-field-by-field/m-p/498976#M138992</link>
      <description>&lt;P&gt;What I've done when I want the X&lt;SUP&gt;th&lt;/SUP&gt;-many/most recent items is the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt;
| eval field_time=_time+"|"+field
| stats values(field_time) as field_time &amp;lt;rest of stats here&amp;gt;
| eval recent_1st=mvindex(field_time,-1), recent_2nd=mvindex(field_time,-2) [, etc etc]
| rex field=recent_1st "(?&amp;lt;when_1st&amp;gt;\d+)\|(?&amp;lt;field_1st&amp;gt;.+)"
| rex field=recent_2nd "(?&amp;lt;when_2nd&amp;gt;\d+)\|(?&amp;lt;field_2nd&amp;gt;.+)"
| ...more rex lines as needed
| table field_1st when_1st field_2nd when_2nd &amp;lt;other fields as desired&amp;gt;
| eval when_1st=strftime(when_1st,"%c"), when_2nd=strftime(when_2nd,"%c) [,etc etc]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Feel free to use different strftime formatting as desired&lt;/P&gt;

&lt;P&gt;You have to combine the time into the field so that it sorts the way you want with &lt;CODE&gt;values()&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 14:36:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-three-latest-values-of-a-field-by-field/m-p/498976#M138992</guid>
      <dc:creator>wmyersas</dc:creator>
      <dc:date>2020-03-23T14:36:46Z</dc:date>
    </item>
  </channel>
</rss>

