<?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 How to calculate difference between multiple fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623342#M216689</link>
    <description>&lt;P&gt;Hi Splunk experts - I have an unusual math problem on my hands and I'm not sure how to deal with it. We are trying to prove how many tickets have been completed, so we are only counting the numbers that show improvement, not the numbers that show the addition of more tickets (following me?).&lt;/P&gt;
&lt;P&gt;Here's the data:&lt;/P&gt;
&lt;P&gt;report_date total&lt;BR /&gt;2022-11-07 4111&lt;BR /&gt;2022-11-08 3764&lt;BR /&gt;2022-11-09 3562&lt;BR /&gt;2022-11-10 3633&lt;BR /&gt;2022-11-11 3694&lt;BR /&gt;2022-11-14 7506&lt;BR /&gt;2022-11-15 12987&lt;BR /&gt;2022-11-16 15159&lt;BR /&gt;2022-11-17 14851&lt;BR /&gt;2022-11-18 14410&lt;BR /&gt;2022-11-21 6674&lt;BR /&gt;2022-11-22 5793&lt;BR /&gt;2022-11-23 5601&lt;/P&gt;
&lt;P&gt;What I am trying to do is determine the difference between the "total" fields, but only when the count goes down. So for example, 11/7 - 11/9 show counts going down (4111-3562=549). But the numbers go up on 11/10, so we don't want to count those. And then the numbers go down again on 11/17, so I would add the difference between 11/16 and 11/17 to the previous 549.&lt;/P&gt;
&lt;P&gt;I feel like I am making this more complicated that it needs to be. Help.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Dec 2022 14:36:37 GMT</pubDate>
    <dc:creator>mistydennis</dc:creator>
    <dc:date>2022-12-06T14:36:37Z</dc:date>
    <item>
      <title>How to calculate difference between multiple fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623342#M216689</link>
      <description>&lt;P&gt;Hi Splunk experts - I have an unusual math problem on my hands and I'm not sure how to deal with it. We are trying to prove how many tickets have been completed, so we are only counting the numbers that show improvement, not the numbers that show the addition of more tickets (following me?).&lt;/P&gt;
&lt;P&gt;Here's the data:&lt;/P&gt;
&lt;P&gt;report_date total&lt;BR /&gt;2022-11-07 4111&lt;BR /&gt;2022-11-08 3764&lt;BR /&gt;2022-11-09 3562&lt;BR /&gt;2022-11-10 3633&lt;BR /&gt;2022-11-11 3694&lt;BR /&gt;2022-11-14 7506&lt;BR /&gt;2022-11-15 12987&lt;BR /&gt;2022-11-16 15159&lt;BR /&gt;2022-11-17 14851&lt;BR /&gt;2022-11-18 14410&lt;BR /&gt;2022-11-21 6674&lt;BR /&gt;2022-11-22 5793&lt;BR /&gt;2022-11-23 5601&lt;/P&gt;
&lt;P&gt;What I am trying to do is determine the difference between the "total" fields, but only when the count goes down. So for example, 11/7 - 11/9 show counts going down (4111-3562=549). But the numbers go up on 11/10, so we don't want to count those. And then the numbers go down again on 11/17, so I would add the difference between 11/16 and 11/17 to the previous 549.&lt;/P&gt;
&lt;P&gt;I feel like I am making this more complicated that it needs to be. Help.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 14:36:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623342#M216689</guid>
      <dc:creator>mistydennis</dc:creator>
      <dc:date>2022-12-06T14:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623343#M216690</link>
      <description>&lt;P&gt;Try something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| streamstats window=1 current=f values(total) as previous_total
| eval diff=if(previous_total &amp;gt; total, previous_total-total, 0)
| streamstats sum(diff) as running_total_diff&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 06 Dec 2022 08:44:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623343#M216690</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-12-06T08:44:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623344#M216691</link>
      <description>&lt;P&gt;When plugged into my search I get an error:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=myindex 
| stats count as total by report_date
| streamstats window=1 current=f value(total) as previous_total 
| eval diff=if(previous_total &amp;gt; total, previous_total-total, 0) 
| streamstats sum(diff) as running_total_diff&lt;/LI-CODE&gt;&lt;P&gt;Error: &lt;SPAN&gt;Error in 'streamstats' command: The argument 'value(total)' is invalid.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 23:04:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623344#M216691</guid>
      <dc:creator>mistydennis</dc:creator>
      <dc:date>2022-12-05T23:04:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623349#M216693</link>
      <description>&lt;P&gt;Should be&lt;/P&gt;&lt;PRE&gt;values(total)&lt;/PRE&gt;&lt;P&gt;Simple typo - eaten "s" &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2022 23:44:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623349#M216693</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-12-05T23:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623422#M216718</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp;for the typo fix &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After plugging in the search, I'm not getting expected results - everything is "0":&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot 2022-12-06 063204.jpg" style="width: 999px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/22882i43C77C010DC3F374/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-12-06 063204.jpg" alt="Screenshot 2022-12-06 063204.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 13:32:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623422#M216718</guid>
      <dc:creator>mistydennis</dc:creator>
      <dc:date>2022-12-06T13:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623425#M216719</link>
      <description>&lt;P&gt;It looks like your field is called mytotal not total - try this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=myindex 
| stats count as total by report_date
| streamstats window=1 current=f values(mytotal) as previous_total 
| eval diff=if(previous_total &amp;gt; mytotal, previous_total-mytotal, 0) 
| streamstats sum(diff) as running_total_diff&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 06 Dec 2022 13:54:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623425#M216719</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-12-06T13:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate difference between multiple fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623426#M216720</link>
      <description>&lt;P&gt;You must have done something differently since you have different field names.&lt;/P&gt;&lt;P&gt;So you probably hit the "if" condition which cannot perform the substraction since it doesn't have one or both of the fields defined and so you land with the "else" value which is zero.&lt;/P&gt;&lt;P&gt;BTW, if report_date is the same as _time, you could use tstats to count the events - it would be way way faster.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2022 13:58:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-difference-between-multiple-fields/m-p/623426#M216720</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2022-12-06T13:58:38Z</dc:date>
    </item>
  </channel>
</rss>

