<?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 do I subtract values from different events and fields based on a common field? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-values-from-different-events-and-fields-based/m-p/470280#M132323</link>
    <description>&lt;P&gt;Try this. Please mark as answer if this works for you.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|union 
   [search 1]
   [search 2]
| stats values(email) as email, sum(request) as request, sum(error) as error by session_id
| eval successful_request=request - error
| fields - error, session_id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 27 Oct 2019 03:05:01 GMT</pubDate>
    <dc:creator>arjunpkishore5</dc:creator>
    <dc:date>2019-10-27T03:05:01Z</dc:date>
    <item>
      <title>How do I subtract values from different events and fields based on a common field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-values-from-different-events-and-fields-based/m-p/470279#M132322</link>
      <description>&lt;P&gt;Please help, I'm stuck on this problem for a while. Basically, lets say I have different events with fields like this. Basically I need a way to subtract a count from two different fields from two different events. Those two events only have 1 common field to somehow tie them together.&lt;/P&gt;

&lt;P&gt;Event1)&lt;BR /&gt;
session_id: 123   error: 1&lt;/P&gt;

&lt;P&gt;Event2)&lt;BR /&gt;
session_id: 123   request: 1  email: &lt;A href="mailto:user1@gmail.com" target="_blank"&gt;user1@gmail.com&lt;/A&gt;&lt;BR /&gt;
session_id: 123   request: 1  email: &lt;A href="mailto:user1@gmail.com" target="_blank"&gt;user1@gmail.com&lt;/A&gt;&lt;BR /&gt;
session_id: 321   request: 1  email: &lt;A href="mailto:user2@gmail.com" target="_blank"&gt;user2@gmail.com&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Result)&lt;BR /&gt;
email                               request     successful_request&lt;BR /&gt;
&lt;A href="mailto:user1@gmail.com" target="_blank"&gt;user1@gmail.com&lt;/A&gt;             2                           1&lt;BR /&gt;
&lt;A href="mailto:user2@gmail.com" target="_blank"&gt;user2@gmail.com&lt;/A&gt;             1                           1&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:45:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-values-from-different-events-and-fields-based/m-p/470279#M132322</guid>
      <dc:creator>thomaszheng</dc:creator>
      <dc:date>2020-09-30T02:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I subtract values from different events and fields based on a common field?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-values-from-different-events-and-fields-based/m-p/470280#M132323</link>
      <description>&lt;P&gt;Try this. Please mark as answer if this works for you.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|union 
   [search 1]
   [search 2]
| stats values(email) as email, sum(request) as request, sum(error) as error by session_id
| eval successful_request=request - error
| fields - error, session_id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Oct 2019 03:05:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-subtract-values-from-different-events-and-fields-based/m-p/470280#M132323</guid>
      <dc:creator>arjunpkishore5</dc:creator>
      <dc:date>2019-10-27T03:05:01Z</dc:date>
    </item>
  </channel>
</rss>

