<?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 get most recent field value in streamstats in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-most-recent-field-value-in-streamstats/m-p/189600#M54619</link>
    <description>&lt;P&gt;I have the following query &lt;BR /&gt;
index=qa sourcetype=xxx (JobName =xxxx)  ClassName=xxxx    | dedup buildNum, jobName, TestName   | streamstats global=f current=f window=1 first(buildNum) as priorBuildNum,             first(Status) as priorStatus by jobName, TestName   | stats latest(Status) as currentStatus by  buildNum,TestName   |table buildNum, TestName   , currentStatus&lt;/P&gt;

&lt;P&gt;I have 1st three columns with the above query . I want to compute the LastPassedBuildNum column ( I have added expected results)&lt;BR /&gt;
Logic would be : if currentStatus is Success --&amp;gt; get the buildNum and display that, if currentStatus is Error --&amp;gt; get the most recent buildNum when test was Success&lt;/P&gt;

&lt;P&gt;buildNum    TestName   currentStatus  Last PassedbuildNum&lt;BR /&gt;
4532    TestName1           Success            4532&lt;BR /&gt;
4532    TestName2           Error                 4531 (assume)&lt;BR /&gt;
4533    TestName1           Success            4533&lt;BR /&gt;
4533    TestName2           Error                 4531(assume)&lt;BR /&gt;
4534    TestName1           Error                 4533 (should be most recent passed buildNum)&lt;BR /&gt;
4534    TestName2           Success            4534&lt;/P&gt;

&lt;P&gt;Could someone help me compute the last column in above table?&lt;/P&gt;

&lt;P&gt;I used foreach too but for some reason, i have not been able to get the desired result&lt;BR /&gt;
Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 02 Jul 2015 18:04:09 GMT</pubDate>
    <dc:creator>pkhimani</dc:creator>
    <dc:date>2015-07-02T18:04:09Z</dc:date>
    <item>
      <title>How to get most recent field value in streamstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-most-recent-field-value-in-streamstats/m-p/189600#M54619</link>
      <description>&lt;P&gt;I have the following query &lt;BR /&gt;
index=qa sourcetype=xxx (JobName =xxxx)  ClassName=xxxx    | dedup buildNum, jobName, TestName   | streamstats global=f current=f window=1 first(buildNum) as priorBuildNum,             first(Status) as priorStatus by jobName, TestName   | stats latest(Status) as currentStatus by  buildNum,TestName   |table buildNum, TestName   , currentStatus&lt;/P&gt;

&lt;P&gt;I have 1st three columns with the above query . I want to compute the LastPassedBuildNum column ( I have added expected results)&lt;BR /&gt;
Logic would be : if currentStatus is Success --&amp;gt; get the buildNum and display that, if currentStatus is Error --&amp;gt; get the most recent buildNum when test was Success&lt;/P&gt;

&lt;P&gt;buildNum    TestName   currentStatus  Last PassedbuildNum&lt;BR /&gt;
4532    TestName1           Success            4532&lt;BR /&gt;
4532    TestName2           Error                 4531 (assume)&lt;BR /&gt;
4533    TestName1           Success            4533&lt;BR /&gt;
4533    TestName2           Error                 4531(assume)&lt;BR /&gt;
4534    TestName1           Error                 4533 (should be most recent passed buildNum)&lt;BR /&gt;
4534    TestName2           Success            4534&lt;/P&gt;

&lt;P&gt;Could someone help me compute the last column in above table?&lt;/P&gt;

&lt;P&gt;I used foreach too but for some reason, i have not been able to get the desired result&lt;BR /&gt;
Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2015 18:04:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-most-recent-field-value-in-streamstats/m-p/189600#M54619</guid>
      <dc:creator>pkhimani</dc:creator>
      <dc:date>2015-07-02T18:04:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to get most recent field value in streamstats</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-most-recent-field-value-in-streamstats/m-p/189601#M54620</link>
      <description>&lt;P&gt;Copy this run-anywhere example into a new search window:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count as build | eval status = "Success Error Success Success Error Error Success"
| makemv status | mvexpand status | streamstats count as build
| streamstats last(eval(case(status="Success", build))) as lastSuccessfulBuild
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;build  lastSuccessfulBuild  status
1      1                    Success
2      1                    Error
3      3                    Success
4      4                    Success
5      4                    Error
6      4                    Error
7      7                    Success 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should be translatable to your problem.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2015 23:06:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-most-recent-field-value-in-streamstats/m-p/189601#M54620</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-07-02T23:06:47Z</dc:date>
    </item>
  </channel>
</rss>

