<?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: Compute row differences in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27181#M5269</link>
    <description>&lt;P&gt;Look at streamstats by s: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Streamstats"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Streamstats&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Feb 2013 11:52:07 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2013-02-11T11:52:07Z</dc:date>
    <item>
      <title>Compute row differences</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27180#M5268</link>
      <description>&lt;P&gt;Hello everyone!&lt;/P&gt;

&lt;P&gt;I have a very simple result table that looks like this:&lt;/P&gt;

&lt;P&gt;_time                                           s                               duration&lt;BR /&gt;
2/10/13 12:20:22.000 PM         21279054471791556300            0&lt;BR /&gt;
2/10/13 12:20:43.000 PM         21279054471791556300            21&lt;BR /&gt;
2/10/13 12:21:07.000 PM         21279054471791556300            45&lt;BR /&gt;
2/10/13 12:21:07.000 PM         21279054471791556300            45&lt;BR /&gt;
2/10/13 12:21:52.000 PM         21279054471791556300            90&lt;BR /&gt;
2/10/13 12:22:26.000 PM         21279054471791556300            124&lt;BR /&gt;
2/10/13 12:22:59.000 PM         21279054471791556300            157&lt;BR /&gt;
2/10/13 12:23:07.000 PM         21279054471791556300            165&lt;BR /&gt;
2/11/13 5:09:16.000 AM          21242230731515268458            131&lt;BR /&gt;
2/11/13 5:09:38.000 AM          21242230731515268458            153&lt;BR /&gt;
2/11/13 5:09:46.000 AM          21242230731515268458            161&lt;BR /&gt;
2/11/13 5:09:53.000 AM          21242230731515268458            168&lt;BR /&gt;
2/11/13 5:09:53.000 AM          21242230731515268458            168&lt;BR /&gt;
2/11/13 5:10:19.000 AM          21242230731515268458            194&lt;BR /&gt;
2/11/13 5:10:24.000 AM          21242230731515268458            199&lt;BR /&gt;
2/11/13 5:10:37.000 AM          21242230731515268458            212&lt;BR /&gt;
2/11/13 5:10:45.000 AM          21242230731515268458            220&lt;BR /&gt;
2/11/13 5:10:50.000 AM          21242230731515268458            225&lt;/P&gt;

&lt;P&gt;And I would like to compute a new field, let say diff, that will contains the difference between each duration, row by row: like this:&lt;/P&gt;

&lt;P&gt;_time                                           s                               duration                diff&lt;BR /&gt;
2/10/13 12:20:22.000 PM         21279054471791556300            0                      / Nothing&lt;BR /&gt;
2/10/13 12:20:43.000 PM         21279054471791556300            21                     21&lt;BR /&gt;
2/10/13 12:21:07.000 PM         21279054471791556300            45                     23&lt;BR /&gt;
2/10/13 12:21:07.000 PM         21279054471791556300            45                     0&lt;BR /&gt;
2/10/13 12:21:52.000 PM         21279054471791556300            90                     45&lt;BR /&gt;
2/10/13 12:22:26.000 PM         21279054471791556300            124                    69&lt;BR /&gt;
2/10/13 12:22:59.000 PM         21279054471791556300            157                    33&lt;BR /&gt;
2/10/13 12:23:07.000 PM         21279054471791556300            165                    8&lt;BR /&gt;
2/11/13 5:09:16.000 AM          21242230731515268458            131                    / Nothing &lt;BR /&gt;
2/11/13 5:09:38.000 AM          21242230731515268458            153                    22&lt;BR /&gt;
2/11/13 5:09:46.000 AM          21242230731515268458            161                    18&lt;BR /&gt;
2/11/13 5:09:53.000 AM          21242230731515268458            168                    7&lt;BR /&gt;
2/11/13 5:09:53.000 AM          21242230731515268458            168                    0&lt;BR /&gt;
2/11/13 5:10:19.000 AM          21242230731515268458            194                    26&lt;BR /&gt;
2/11/13 5:10:24.000 AM          21242230731515268458            199                    5&lt;BR /&gt;
2/11/13 5:10:37.000 AM          21242230731515268458            212                    13&lt;BR /&gt;
2/11/13 5:10:45.000 AM          21242230731515268458            220                    8&lt;BR /&gt;
2/11/13 5:10:50.000 AM          21242230731515268458            225                    5&lt;/P&gt;

&lt;P&gt;I have tried to use the delta command, but it doesn't work because events from several s can occur at the same time.&lt;/P&gt;

&lt;P&gt;I want to avoid using double makemv / mvexpand and compute the difference between all and filter after, as it will cost a lot of time (n square) and I really only need the duration(n) - duration(n-1) value&lt;/P&gt;

&lt;P&gt;Thanks a lot!&lt;/P&gt;

&lt;P&gt;Guilhem&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2013 11:40:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27180#M5268</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-02-11T11:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Compute row differences</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27181#M5269</link>
      <description>&lt;P&gt;Look at streamstats by s: &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Streamstats"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Streamstats&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2013 11:52:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27181#M5269</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-02-11T11:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: Compute row differences</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27182#M5270</link>
      <description>&lt;P&gt;OK, it was quite "simple", thanks for pointing out the streamstat command, I'm not familiar with it. Anyway here the solution:&lt;/P&gt;

&lt;P&gt;| streamstats list(duration) as duration2 c(duration) as count by s&lt;BR /&gt;
| eval diff = mvindex(duration2, count-2)&lt;BR /&gt;
| eval diff = duration-diff&lt;/P&gt;

&lt;P&gt;Note that I have to count the number of values of the duration2, so I can get the before last mvindex&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;EDIT&lt;/P&gt;

&lt;P&gt;The updated (much simplier) version is:&lt;/P&gt;

&lt;P&gt;| streamstats current=f last(duration) as last_duration by s &lt;BR /&gt;
| eval diff = duration - last_duration&lt;/P&gt;

&lt;P&gt;Thanks to martin_mueller&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:17:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27182#M5270</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2020-09-28T13:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Compute row differences</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27183#M5271</link>
      <description>&lt;P&gt;Consider this to get around the list/mvindex thingy:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | streamstats current=f last(duration) as last_duration by s | eval diff = duration - last_duration
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Feb 2013 13:25:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27183#M5271</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-02-11T13:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Compute row differences</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27184#M5272</link>
      <description>&lt;P&gt;Be carefull thow, as I have just discovered, the lis() function only returns the first 100 results, so it may be convenient to use something else (penultimate duration value, instead of list).&lt;/P&gt;

&lt;P&gt;I will update the answer when I found out how to find the penultimate value of a field using stats.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2013 14:29:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27184#M5272</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-02-11T14:29:01Z</dc:date>
    </item>
    <item>
      <title>Re: Compute row differences</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27185#M5273</link>
      <description>&lt;P&gt;list(duration) sounds quite cumbersome when you're basically just looking for last(duration)...&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2013 14:43:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27185#M5273</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-02-11T14:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Compute row differences</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27186#M5274</link>
      <description>&lt;P&gt;Perfect, using the current=f to get the last-but-one value is clever!&lt;/P&gt;

&lt;P&gt;I update the answer.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2013 14:47:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27186#M5274</guid>
      <dc:creator>guilhem</dc:creator>
      <dc:date>2013-02-11T14:47:23Z</dc:date>
    </item>
    <item>
      <title>Re: Compute row differences</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27187#M5275</link>
      <description>&lt;P&gt;Could you explain what current=f  is used for here. Also last(x) takes us to the oldest entry for that s isn't it. so how is it being used here exactly. sorry for the naive doubts. im still a newbie.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 11:26:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Compute-row-differences/m-p/27187#M5275</guid>
      <dc:creator>AshimaE</dc:creator>
      <dc:date>2017-06-12T11:26:13Z</dc:date>
    </item>
  </channel>
</rss>

