<?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: How to get a specific result with stats latest when two events have the same timestamp? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454473#M78675</link>
    <description>&lt;P&gt;He says also that they have the "same time".&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jul 2019 15:03:30 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-07-08T15:03:30Z</dc:date>
    <item>
      <title>How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454459#M78661</link>
      <description>&lt;P&gt;Hi, please consider this example.csv:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;device   result    _time
apollo1  passed  2019-06-28
apollo1  failed  2019-06-28
zeus8    passed  2019-06-23
zeus8    failed  2019-06-23
zeus8    error   2019-06-23
hermes3  failed  2019-06-23 //Edit #1
hermes3  failed  2019-06-23 //Edit #1
apollo1  passed  2019-06-20  //Edit #1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note: This is just an example. My real CSV has thousands of devices.&lt;/P&gt;

&lt;P&gt;I want to return the latest entry based on the &lt;CODE&gt;device&lt;/CODE&gt; value. When a device appears more than once with a duplicated timestamp and different &lt;CODE&gt;result&lt;/CODE&gt; value, the event where result = passed should appear. Else, show the event where result is failed or error. &lt;STRONG&gt;What query do I need to do that?&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;My current query ( &lt;CODE&gt;|inputlookup example.csv |stats latest by device&lt;/CODE&gt;)  does not guarantee the event where result = passed will appear when a device shows up multiple times with with the same latest timestamp and different &lt;CODE&gt;result&lt;/CODE&gt; values.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;//Edit #1 below&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;The query I need would produce the table below&lt;/STRONG&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;device   result    _time
apollo1  passed  2019-06-28
zeus8    passed  2019-06-23
hermes3  failed  2019-06-23
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The query would 1) show only the latest device with the latest &lt;CODE&gt;_time&lt;/CODE&gt;, 2) if a device is listed twice with the same &lt;CODE&gt;_time&lt;/CODE&gt; and a different &lt;CODE&gt;result&lt;/CODE&gt;, show just the device where result = passed. Else display the event with either failed or error, and 3) since conditions 1 and 2 are followed, each device should only appear once.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 17:39:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454459#M78661</guid>
      <dc:creator>russell120</dc:creator>
      <dc:date>2019-07-02T17:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454460#M78662</link>
      <description>&lt;P&gt;@russell120- Try below&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|inputlookup example.csv |sort - _time device |streamstats count as i by device| dedup device
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2019 18:08:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454460#M78662</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2019-07-02T18:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454461#M78663</link>
      <description>&lt;P&gt;@Vijeta Hi, that does not show the latest event that prioritizes where &lt;CODE&gt;result&lt;/CODE&gt; = &lt;CODE&gt;passed&lt;/CODE&gt; when a device has 2 (or more) events with the same timestamp and &lt;EM&gt;different&lt;/EM&gt; &lt;CODE&gt;result&lt;/CODE&gt; value. Please reference this condition from the original question:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;When a device appears more than once with a duplicated timestamp and different result value, the event where result = passed should appear. Else, show the event where result is failed or error. What query do I need to do that?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 02 Jul 2019 18:23:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454461#M78663</guid>
      <dc:creator>russell120</dc:creator>
      <dc:date>2019-07-02T18:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454462#M78664</link>
      <description>&lt;P&gt;@russell120 Sorry for misinterpreting the question , can you try like below-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  |inputlookup example.csv|stats count(eval(result="passed")) as PS, count(eval(result!="passed")) as NP , values(result) as result by _time device|eval result=if(PS&amp;gt;=1 and NP&amp;gt;0,"passed",result)| fields _time device result
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2019 18:46:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454462#M78664</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2019-07-02T18:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454463#M78665</link>
      <description>&lt;P&gt;It's okay. I edited my initial post and added "//Edit #1" to where I updated it to more accurately reflect my real CSV. What you most recently posted almost accomplished the solution but there are duplicated devices from previous dates.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 14:03:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454463#M78665</guid>
      <dc:creator>russell120</dc:creator>
      <dc:date>2019-07-03T14:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454464#M78666</link>
      <description>&lt;P&gt;Hi @russell120 you can use stats latest at the end of above search like this-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; |inputlookup example.csv|stats count(eval(result="passed")) as PS, count(eval(result!="passed")) as NP , values(result) as result by _time device|eval result=if(PS&amp;gt;=1 and NP&amp;gt;0,"passed",result)| fields _time device result| stats latest by device
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Jul 2019 14:42:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454464#M78666</guid>
      <dc:creator>Vijeta</dc:creator>
      <dc:date>2019-07-03T14:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454465#M78667</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|inputlookup example.csv
| sort - device _time result
| dedup device
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note: this does assume error,failed and passed are the only options, where passed conveniently happens to be the furthest down in alphabetic order.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2019 14:57:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454465#M78667</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-07-03T14:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454466#M78668</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval raw="device=apollo1,result=passed,_time=2019-06-28 device=apollo1,result=failed,_time=2019-06-28 device=zeus8,result=passed,_time=2019-06-23 device=zeus8,result=failed,_time=2019-06-23 device=zeus8,result=error,_time=2019-06-23 device=hermes3,result=failed,_time=2019-06-23 device=hermes3,result=failed,_time=2019-06-23 device=apollo1,result=passed,_time=2019-06-20"
| makemv raw
| mvexpand raw
| rename raw AS _raw
| kv
| eval _time = strptime(time, "%Y-%m-%d")
| fields - _raw time

| rename COMMENT AS "Everything above generates sample event data; everything below is your solution"

| eval sortme = if(result="passed", 0, 1)
| sort 0 _time device sortme
| fields - sortme
| dedup _time device
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Jul 2019 04:11:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454466#M78668</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-06T04:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454467#M78669</link>
      <description>&lt;P&gt;This solution does not prefer &lt;CODE&gt;result=passed&lt;/CODE&gt; over all other values in a time-host tie.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jul 2019 04:13:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454467#M78669</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-06T04:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454468#M78670</link>
      <description>&lt;P&gt;Why not? result is taken along in the sort, so for any items with same device and _time, passed would end up on top.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jul 2019 10:17:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454468#M78670</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-07-06T10:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454469#M78671</link>
      <description>&lt;P&gt;Read what OP said.  This is the key detail on his request.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Jul 2019 15:18:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454469#M78671</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-06T15:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454470#M78672</link>
      <description>&lt;P&gt;Yes, and unless I'm completely missing something, my solution does just that. It will sort by device, within that by time and within that by result (all decending) and then takes the top row per device using dedup. Sorting result decending means if there was a "passed" on the last date, it will show on top.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 05:53:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454470#M78672</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-07-08T05:53:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454471#M78673</link>
      <description>&lt;P&gt;He is clearly implying that the &lt;CODE&gt;passed&lt;/CODE&gt; event might not be on top.  Otherwise the solution is trivial.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 14:38:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454471#M78673</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-08T14:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454472#M78674</link>
      <description>&lt;P&gt;That is why I'm including a sort.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 14:53:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454472#M78674</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-07-08T14:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454473#M78675</link>
      <description>&lt;P&gt;He says also that they have the "same time".&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jul 2019 15:03:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454473#M78675</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-08T15:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454474#M78676</link>
      <description>&lt;P&gt;Yes, again: that is why I include the result field into the sorting. Since passed comes after error and fail in the alphabet, if there are multiple entries with the same time for some device, the pass entry will end up on top.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 06:24:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454474#M78676</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-07-09T06:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454475#M78677</link>
      <description>&lt;P&gt;Ah, you are assuming that no states are farther down the alphabet than &lt;CODE&gt;p&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 19:06:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454475#M78677</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-07-09T19:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a specific result with stats latest when two events have the same timestamp?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454476#M78678</link>
      <description>&lt;P&gt;Exactly, as clearly mentioned in my answer &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 06:13:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-get-a-specific-result-with-stats-latest-when-two-events/m-p/454476#M78678</guid>
      <dc:creator>FrankVl</dc:creator>
      <dc:date>2019-07-10T06:13:06Z</dc:date>
    </item>
  </channel>
</rss>

