<?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 use streamstats to display the last current result? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-streamstats-to-display-the-last-current-result/m-p/326811#M97372</link>
    <description>&lt;P&gt;i am getting the results with your query!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
|  eval raw="Adam2/2/201723 Adam2/1/201712 Adam2/3/201733" 
| makemv raw
| mvexpand raw 
| rex field=raw "(?&amp;lt;Username&amp;gt;[^\d]+)(?&amp;lt;TransactDate&amp;gt;\d\/\d\/\d{4})(?&amp;lt;PaymentNumber&amp;gt;\d)(?&amp;lt;NextPaymentNumber&amp;gt;\d)" 
|  fields- raw _time | sort- TransactDate | streamstats   last("PaymentNumber") as NextPaymentNumber 
| table Username, "TransactDate","PaymentNumber", NextPaymentNumber
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;can you try putting table command  &lt;CODE&gt;| table Username, "TransactDate","Payment Number", NextPaymentNumber&lt;/CODE&gt; before &lt;CODE&gt;streamstats&lt;/CODE&gt; and see if you are getting a proper table with descending transactdate.&lt;/P&gt;</description>
    <pubDate>Thu, 25 Jan 2018 10:38:28 GMT</pubDate>
    <dc:creator>mayurr98</dc:creator>
    <dc:date>2018-01-25T10:38:28Z</dc:date>
    <item>
      <title>How to use streamstats to display the last current result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-streamstats-to-display-the-last-current-result/m-p/326810#M97371</link>
      <description>&lt;P&gt;Hi all, &lt;/P&gt;

&lt;P&gt;I am trying to use streamstats to display an event for a particular user, their current Payment Number for this month, and the subsequent Payment number for the next event. (Do note that I sort the date in reverse order).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | sort  -TransactDate
  | streamstats current=f window=1 last("Payment Number") as NextPaymentNumber  
  | table  Username,  "TransactDate","Payment Number", NextPaymentNumber
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I almost get the result I want as below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; Username       TransactDate         Payment Number      NextPaymentNumber
    Adam                   2/2/2017               2                       3
    Adam                   2/1/2017               1                       2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, what I need is something like below:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Username       TransactDate         Payment Number      NextPaymentNumber
     Adam                   2/3/2017               3                       3
    Adam                   2/2/2017               2                       3
    Adam                   2/1/2017               1                       2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Where the record on 2/3/2017 is the latest record, and the latest and maximum Payment number is 3.&lt;/P&gt;

&lt;P&gt;Please advice how could I achieve that? Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 10:05:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-streamstats-to-display-the-last-current-result/m-p/326810#M97371</guid>
      <dc:creator>desslerlee</dc:creator>
      <dc:date>2018-01-25T10:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use streamstats to display the last current result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-streamstats-to-display-the-last-current-result/m-p/326811#M97372</link>
      <description>&lt;P&gt;i am getting the results with your query!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
|  eval raw="Adam2/2/201723 Adam2/1/201712 Adam2/3/201733" 
| makemv raw
| mvexpand raw 
| rex field=raw "(?&amp;lt;Username&amp;gt;[^\d]+)(?&amp;lt;TransactDate&amp;gt;\d\/\d\/\d{4})(?&amp;lt;PaymentNumber&amp;gt;\d)(?&amp;lt;NextPaymentNumber&amp;gt;\d)" 
|  fields- raw _time | sort- TransactDate | streamstats   last("PaymentNumber") as NextPaymentNumber 
| table Username, "TransactDate","PaymentNumber", NextPaymentNumber
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;can you try putting table command  &lt;CODE&gt;| table Username, "TransactDate","Payment Number", NextPaymentNumber&lt;/CODE&gt; before &lt;CODE&gt;streamstats&lt;/CODE&gt; and see if you are getting a proper table with descending transactdate.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 10:38:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-streamstats-to-display-the-last-current-result/m-p/326811#M97372</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-01-25T10:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use streamstats to display the last current result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-streamstats-to-display-the-last-current-result/m-p/326812#M97373</link>
      <description>&lt;P&gt;Do you want to add an extra row for each user with latest date (max date +1) and latest (max + 1) PaymentNumber?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jan 2018 21:47:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-streamstats-to-display-the-last-current-result/m-p/326812#M97373</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-01-25T21:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to use streamstats to display the last current result?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-streamstats-to-display-the-last-current-result/m-p/326813#M97374</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search that gets the payments (most recent first)
| reverse
| streamstats count as payno by Username
| reverse
| streamstats current=f window=1 last(payno) as nextpayno by Username
| eval nextpayno = coalesce(nextpayno, payno)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Jan 2018 00:53:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-streamstats-to-display-the-last-current-result/m-p/326813#M97374</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-01-26T00:53:10Z</dc:date>
    </item>
  </channel>
</rss>

