<?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 join events on an id and subtract values from same named field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-events-on-an-id-and-subtract-values-from-same-named/m-p/467267#M131506</link>
    <description>&lt;P&gt;thanks aberkov, that did the trick.  I just needed to add an 'AND' between the conditions on line 5, and add the 'chart p95(durationA) p95(durationB) p95(delta_duration)' at the end&lt;/P&gt;</description>
    <pubDate>Wed, 18 Dec 2019 21:55:18 GMT</pubDate>
    <dc:creator>econstantin</dc:creator>
    <dc:date>2019-12-18T21:55:18Z</dc:date>
    <item>
      <title>How to join events on an id and subtract values from same named field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-events-on-an-id-and-subtract-values-from-same-named/m-p/467264#M131503</link>
      <description>&lt;P&gt;I've got two different events that have identical data points, including an id.  I'd like to join the events on an id and then find the delta between a field that's found in each one.&lt;/P&gt;

&lt;P&gt;For example&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Event1: { type='eventA', id: '123', duration: 500}
Event2: { type='eventB' ,id: '123', duration: 550}
Event3: { type='eventB' ,id: '456', duration: 200}  // this one should be ignored since it doesn't have an id that found in both eventA and eventB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'd like to get some output like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;p95(eventA_duration)  p95(eventB_duration)  p95(delta_duration)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;(i.e. I think there'd be something in there like:  &lt;CODE&gt;| eval delta_duration = eventB_duration - eventA_duration&lt;/CODE&gt; )&lt;/P&gt;

&lt;P&gt;Many thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 02:17:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-events-on-an-id-and-subtract-values-from-same-named/m-p/467264#M131503</guid>
      <dc:creator>econstantin</dc:creator>
      <dc:date>2019-12-18T02:17:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to join events on an id and subtract values from same named field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-events-on-an-id-and-subtract-values-from-same-named/m-p/467265#M131504</link>
      <description>&lt;P&gt;So eval will only work if you have both fields in the same row, which won't work until you've aggregated your two rows into one. That being said, you have to rename the fields so as not to lose them when you convert them (or you can make it a multivalue field and deal with some splitting and other stuff). I'd suggest something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;baseSearch
| eval durationEventA = if(type="eventA", duration, null())
| eval durationEventB = if(type="eventB", duration, null())
| stats values(durationEventA) as durationEventA, values(durationEventB) as durationEventB by id
| where isnotnull(durationEventA) isnotnull(durationEventB)
| eval delta_duration= durationEventB - durationEventA
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What I'm doing here: creating two fields on each log that will either be null or have a duration, then aggregating them by id, filtering out those that don't have both, and taking the delta.&lt;/P&gt;

&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 16:53:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-events-on-an-id-and-subtract-values-from-same-named/m-p/467265#M131504</guid>
      <dc:creator>aberkow</dc:creator>
      <dc:date>2019-12-18T16:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to join events on an id and subtract values from same named field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-events-on-an-id-and-subtract-values-from-same-named/m-p/467266#M131505</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="YouShouldAlwaysSpecifyAnIndex" AND sourcetype="AndSourcetypeToo"
| eventstats count(eval(type="eventA")) AS eventAcount BY id
| where eventAcount &amp;gt; 0
| eval {type}_duration = duration
| eventstats range(duration) AS delta_duration BY ID
| stats perc95(eventA_duration) perc95(eventB_duration) perc95(delta_duration)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Dec 2019 19:57:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-events-on-an-id-and-subtract-values-from-same-named/m-p/467266#M131505</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-12-18T19:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to join events on an id and subtract values from same named field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-join-events-on-an-id-and-subtract-values-from-same-named/m-p/467267#M131506</link>
      <description>&lt;P&gt;thanks aberkov, that did the trick.  I just needed to add an 'AND' between the conditions on line 5, and add the 'chart p95(durationA) p95(durationB) p95(delta_duration)' at the end&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 21:55:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-join-events-on-an-id-and-subtract-values-from-same-named/m-p/467267#M131506</guid>
      <dc:creator>econstantin</dc:creator>
      <dc:date>2019-12-18T21:55:18Z</dc:date>
    </item>
  </channel>
</rss>

