<?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 tweak streamstats function to get sum of differences from hand picked events rather than regular streamstats functions ? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-tweak-streamstats-function-to-get-sum-of-differences-from/m-p/365166#M107698</link>
    <description>&lt;P&gt;Thank You &lt;BR /&gt;
 that was an awesome explanation! &lt;/P&gt;</description>
    <pubDate>Wed, 16 Aug 2017 16:25:54 GMT</pubDate>
    <dc:creator>nittalasub</dc:creator>
    <dc:date>2017-08-16T16:25:54Z</dc:date>
    <item>
      <title>how to tweak streamstats function to get sum of differences from hand picked events rather than regular streamstats functions ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-tweak-streamstats-function-to-get-sum-of-differences-from/m-p/365164#M107696</link>
      <description>&lt;P&gt;Streamstats can produce sum of differences like &lt;/P&gt;

&lt;P&gt;(fieldB- fieldA)+ (fieldC-fieldB)+(fieldD - fieldC) = a total of 30 min.&lt;/P&gt;

&lt;P&gt;Can we achieve this evaluation through streamstats ? (fieldB - fieldA)+(fieldD - fieldC) ==&amp;gt;  (10 + 10 = 20 min.) ???&lt;/P&gt;

&lt;P&gt;(PFA Image which poses the question in a understandable manner)&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 05:18:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-tweak-streamstats-function-to-get-sum-of-differences-from/m-p/365164#M107696</guid>
      <dc:creator>nittalasub</dc:creator>
      <dc:date>2017-08-15T05:18:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to tweak streamstats function to get sum of differences from hand picked events rather than regular streamstats functions ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-tweak-streamstats-function-to-get-sum-of-differences-from/m-p/365165#M107697</link>
      <description>&lt;P&gt;Okay, so, first, mathematically, because of the associative, commutative and identity properties of numbers,  (B-A) + (C-B) + (D-C) is always going to equal (D-A).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  (B - A) + (C - B) + (D - C) 
= (B + -A) + (C + -B) + (D + -C) 
= (-A + B) + (-B + C) + (-C + D)  
=  -A +  B + -B  +  C + -C  + D
=  -A + (B + -B) + (C + -C) + D
=  -A +    0     +    0     + D
= -A + D
=  D + -A
=  D - A 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Second, assuming that your events have an ID in common, and you want total duration (B-A + D-C), you can achieve this.  You don't actually need &lt;CODE&gt;streamstats&lt;/CODE&gt; for this, though.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your base search
| eval duration=case(event="A",-fieldA, event="B",fieldB, event="C",-fieldC, event="D",fieldD, true(),null())
| stats sum(duration) as duration by CommonID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or, assuming you wanted to keep event D&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats sum(duration) as duration by CommonID
| where event="D"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Finally, if you need something more complex, then we can help you with that as well, but we would need specifications for what you were doing, and to know the exact fields for reference.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 22:00:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-tweak-streamstats-function-to-get-sum-of-differences-from/m-p/365165#M107697</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-08-15T22:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to tweak streamstats function to get sum of differences from hand picked events rather than regular streamstats functions ?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-tweak-streamstats-function-to-get-sum-of-differences-from/m-p/365166#M107698</link>
      <description>&lt;P&gt;Thank You &lt;BR /&gt;
 that was an awesome explanation! &lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2017 16:25:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-tweak-streamstats-function-to-get-sum-of-differences-from/m-p/365166#M107698</guid>
      <dc:creator>nittalasub</dc:creator>
      <dc:date>2017-08-16T16:25:54Z</dc:date>
    </item>
  </channel>
</rss>

