<?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 Calculating a sum with conditions in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculating-a-sum-with-conditions/m-p/374626#M110109</link>
    <description>&lt;P&gt;Hi all!&lt;/P&gt;

&lt;P&gt;The case is that I want to calculate sum of purchase price of the applications where the application status is either c(contacted) or n(new). There's also multiple other application statuses. Each Splunk event has a unique ID for each event so I will first dedup the ID out so the latest application status with unique ID will be present only. The issue is that I want to calculate the sum, where the application status is either c or n. If application status search is used in query it won't include won(w) and lost(l) application to the search thus calculating sum of applications which status has already been changed to other status than c or n. I've tried to use &lt;EM&gt;where&lt;/EM&gt; command but I don't get any results with that.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Here's my query:&lt;/STRONG&gt;&lt;BR /&gt;
 index=aa sourcetype=bb&lt;BR /&gt;
| dedup ID&lt;BR /&gt;
| eval subtotal=0&lt;BR /&gt;
| foreach summa [eval subtotal = subtotal + '&amp;lt;&amp;gt;']&lt;BR /&gt;
| chart sum(subtotal) by userID &lt;BR /&gt;
| where applicationStatus=c OR applicationStatus=n&lt;BR /&gt;
| sort sum(subtotal)&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Here's another query:&lt;/STRONG&gt;&lt;BR /&gt;
Issue with this one is that if the application status has been changed to w(won) it wont effect to result&lt;/P&gt;

&lt;P&gt;index=aa sourcetype=bb applicationStatus=n OR c&lt;BR /&gt;
| dedup ID&lt;BR /&gt;
| eval subtotal=0&lt;BR /&gt;
| foreach summa [eval subtotal = subtotal + '&amp;lt;&amp;gt;']&lt;BR /&gt;
| chart sum(subtotal) by userID &lt;BR /&gt;
| sort sum(subtotal)&lt;/P&gt;</description>
    <pubDate>Thu, 05 Oct 2017 07:10:48 GMT</pubDate>
    <dc:creator>Jurala</dc:creator>
    <dc:date>2017-10-05T07:10:48Z</dc:date>
    <item>
      <title>Calculating a sum with conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-a-sum-with-conditions/m-p/374626#M110109</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;

&lt;P&gt;The case is that I want to calculate sum of purchase price of the applications where the application status is either c(contacted) or n(new). There's also multiple other application statuses. Each Splunk event has a unique ID for each event so I will first dedup the ID out so the latest application status with unique ID will be present only. The issue is that I want to calculate the sum, where the application status is either c or n. If application status search is used in query it won't include won(w) and lost(l) application to the search thus calculating sum of applications which status has already been changed to other status than c or n. I've tried to use &lt;EM&gt;where&lt;/EM&gt; command but I don't get any results with that.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Here's my query:&lt;/STRONG&gt;&lt;BR /&gt;
 index=aa sourcetype=bb&lt;BR /&gt;
| dedup ID&lt;BR /&gt;
| eval subtotal=0&lt;BR /&gt;
| foreach summa [eval subtotal = subtotal + '&amp;lt;&amp;gt;']&lt;BR /&gt;
| chart sum(subtotal) by userID &lt;BR /&gt;
| where applicationStatus=c OR applicationStatus=n&lt;BR /&gt;
| sort sum(subtotal)&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Here's another query:&lt;/STRONG&gt;&lt;BR /&gt;
Issue with this one is that if the application status has been changed to w(won) it wont effect to result&lt;/P&gt;

&lt;P&gt;index=aa sourcetype=bb applicationStatus=n OR c&lt;BR /&gt;
| dedup ID&lt;BR /&gt;
| eval subtotal=0&lt;BR /&gt;
| foreach summa [eval subtotal = subtotal + '&amp;lt;&amp;gt;']&lt;BR /&gt;
| chart sum(subtotal) by userID &lt;BR /&gt;
| sort sum(subtotal)&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2017 07:10:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-a-sum-with-conditions/m-p/374626#M110109</guid>
      <dc:creator>Jurala</dc:creator>
      <dc:date>2017-10-05T07:10:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a sum with conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-a-sum-with-conditions/m-p/374627#M110110</link>
      <description>&lt;P&gt;i think your problem with the first query is that &lt;CODE&gt;chart&lt;/CODE&gt; isn't giving you a field called &lt;STRONG&gt;applicationStatus&lt;/STRONG&gt;. it should only be giving you fields like &lt;STRONG&gt;sum(subtotal): userId1&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;could you do something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    index=aa sourcetype=bb
    | dedup ID
    |eventstats sum(summa) as grandTotal by userId
    |stats sum(summa) as subTotal max(grandTotal) as grandTotal by userId applicationStatus
    |search applicationStatus="c" OR applicationStatus="n"
    |stats sum(subTotal) as subTotal max(grandTotal) as grandTotal by userId
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Oct 2017 12:43:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-a-sum-with-conditions/m-p/374627#M110110</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-10-05T12:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating a sum with conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-a-sum-with-conditions/m-p/374628#M110111</link>
      <description>&lt;P&gt;That's it, thanks a lot!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2017 07:44:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-a-sum-with-conditions/m-p/374628#M110111</guid>
      <dc:creator>Jurala</dc:creator>
      <dc:date>2017-10-06T07:44:15Z</dc:date>
    </item>
  </channel>
</rss>

