<?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: Calculated the percent difference between two values in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62287#M1376</link>
    <description>&lt;P&gt;Okay I think I know what the problem is. I changed the calculation to this for testing purposes:&lt;BR /&gt;
    "| eval percent_difference=(max(listSelect))"&lt;BR /&gt;
I wanted to see if it could at least pick out the higher of the two listSelects. It can't. Instead, it just lists both listSelects values. It's as if the two listSelects are from two separate searches or something...&lt;/P&gt;</description>
    <pubDate>Sat, 02 Oct 2010 00:43:06 GMT</pubDate>
    <dc:creator>Branden</dc:creator>
    <dc:date>2010-10-02T00:43:06Z</dc:date>
    <item>
      <title>Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62277#M1366</link>
      <description>&lt;P&gt;This is a tricky one (or is it?)...&lt;/P&gt;

&lt;P&gt;I have indexed Splunk data that looks like this (using multikv):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;device_name     host    list(Select)    list(Disk)      difference
vpath0        xyz     19072176        fscsi2/hdisk28  13409 
                        19058767        fscsi3/hdisk56
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'd like to be alerted if the difference between the two "list(Select)" fields is greater than 5%. I know how to do the math on paper, but I can't figure out how to apply it to Splunk. Essentially, I need to divide the "difference" by value of the higher "list(Select)", then multiply by 100. &lt;/P&gt;

&lt;P&gt;I've been dabbling with this, but now I'm wondering if it's even possible.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2010 20:51:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62277#M1366</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-01T20:51:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62278#M1367</link>
      <description>&lt;P&gt;You can use the &lt;A href="http://www.splunk.com/base/Documentation/latest/SearchReference/Eval" rel="nofollow"&gt;eval&lt;/A&gt; command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search |  eval percent_difference=(difference/max(list(Select))*100)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then set up a custom alert condition that hits when percent_difference &amp;gt; 5.&lt;/P&gt;

&lt;P&gt;If this doesn't work try renaming your list(Select) to a more friendly name (without parenthesis).&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;[Edit:]&lt;/STRONG&gt;
Ok, playing around with your query and my data I noticed that the list(Select) didn't return a numerical value list for me, which caused the calculation of percent_difference to fail. Try adding a tonumber() (added in 4.1.4 or 4.1.5, so you need a recent version for this to work) into your query as such:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="datapath-device" earliest=-2h| rex "^DEV#:\s+(?&amp;lt;dev_no&amp;gt;\d+)\s+DEVICE NAME:\s+(?&amp;lt;device_name&amp;gt;\S+)\s+TYPE:\s+(?&amp;lt;type&amp;gt;\d+)\s+POLICY:\s+(?&amp;lt;policy&amp;gt;\S+)" | rex "SERIAL:\s+(?&amp;lt;serial&amp;gt;\S+)" | multikv | stats list(Select) as listSelect, list(Disk), range(Select) as difference by device_name, host | eval percent_difference=((difference/max(tonumber(listSelect)))*100) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If that doesn't work, use eventstats instead of regular stats as such:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="datapath-device" earliest=-2h| rex "^DEV#:\s+(?&amp;lt;dev_no&amp;gt;\d+)\s+DEVICE NAME:\s+(?&amp;lt;device_name&amp;gt;\S+)\s+TYPE:\s+(?&amp;lt;type&amp;gt;\d+)\s+POLICY:\s+(?&amp;lt;policy&amp;gt;\S+)" | rex "SERIAL:\s+(?&amp;lt;serial&amp;gt;\S+)" | multikv | eventstats list(Select) as listSelect, list(Disk), range(Select) as difference by device_name, host | eval percent_difference=((difference/max(tonumber(listSelect)))*100) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;[Edit2]&lt;/STRONG&gt;
What about this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="datapath-device" earliest=-2h| rex "^DEV#:\s+(?&amp;lt;dev_no&amp;gt;\d+)\s+DEVICE NAME:\s+(?&amp;lt;device_name&amp;gt;\S+)\s+TYPE:\s+(?&amp;lt;type&amp;gt;\d+)\s+POLICY:\s+(?&amp;lt;policy&amp;gt;\S+)" | rex "SERIAL:\s+(?&amp;lt;serial&amp;gt;\S+)" | multikv | stats list(Select) as listSelect, list(Disk), range(Select) as difference by device_name, host | eventstats max(listSelect) as maxSelect | eval percent_difference=((difference/maxSelect)*100)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;[EDIT 3:]
how about streamstats?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="datapath-device" earliest=-2h| rex "^DEV#:\s+(?&amp;lt;dev_no&amp;gt;\d+)\s+DEVICE NAME:\s+(?&amp;lt;device_name&amp;gt;\S+)\s+TYPE:\s+(?&amp;lt;type&amp;gt;\d+)\s+POLICY:\s+(?&amp;lt;policy&amp;gt;\S+)" | rex "SERIAL:\s+(?&amp;lt;serial&amp;gt;\S+)" | multikv | stats list(Select) as listSelect, list(Disk), range(Select) as difference by device_name, host | streamstats max(listSelect) as maxSelect window=1 | eval percent_difference=((difference/maxSelect)*100)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Oct 2010 21:59:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62278#M1367</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-01T21:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62279#M1368</link>
      <description>&lt;P&gt;Thank you very much for your reply. &lt;BR /&gt;
I had to change the list(Select) field name like you said, no big deal.&lt;BR /&gt;
I ran the query with the eval command, but I don't see the result anywhere. Shouldn't percent_difference show up as a field?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2010 22:39:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62279#M1368</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-01T22:39:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62280#M1369</link>
      <description>&lt;P&gt;I also modified the eval command a bit to look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval percent_difference=((difference/max(listSelect))*100)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Still not sure why it doesn't appear as a field "percent_difference" though...&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2010 22:42:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62280#M1369</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-01T22:42:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62281#M1370</link>
      <description>&lt;P&gt;@Branden, try adding a &lt;CODE&gt;| table percent_difference&lt;/CODE&gt; at the end of your search. If it calculates it it should show.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2010 22:50:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62281#M1370</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-01T22:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62282#M1371</link>
      <description>&lt;P&gt;Oh yeah and oops, not sure why i put a &lt;CODE&gt;-&lt;/CODE&gt; in there instead of a &lt;CODE&gt;/&lt;/CODE&gt;. Brain fart I guess &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2010 22:51:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62282#M1371</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-01T22:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62283#M1372</link>
      <description>&lt;P&gt;Hmmm.... not showing any results when I do that. I wonder if it's not calculating right...&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2010 23:14:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62283#M1372</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-01T23:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62284#M1373</link>
      <description>&lt;P&gt;If it helps, here's my exact query:&lt;/P&gt;

&lt;P&gt;sourcetype="datapath-device" earliest=-2h| rex "^DEV#:\s+(?&lt;DEV_NO&gt;\d+)\s+DEVICE NAME:\s+(?&lt;DEVICE_NAME&gt;\S+)\s+TYPE:\s+(?&lt;TYPE&gt;\d+)\s+POLICY:\s+(?&lt;POLICY&gt;\S+)" | rex "SERIAL:\s+(?&lt;SERIAL&gt;\S+)" | multikv | stats list(Select) as listSelect, list(Disk), range(Select) as difference by device_name, host |  eval percent_difference=((difference/max(listSelect))*100)&lt;/SERIAL&gt;&lt;/POLICY&gt;&lt;/TYPE&gt;&lt;/DEVICE_NAME&gt;&lt;/DEV_NO&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 09:18:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62284#M1373</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2020-09-28T09:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62285#M1374</link>
      <description>&lt;P&gt;@ Branden I edited the answer a bit based on your query since this is rather long...&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 00:26:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62285#M1374</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-02T00:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62286#M1375</link>
      <description>&lt;P&gt;Thank you again for the help.&lt;BR /&gt;
Unfortunately, neither solution works. "tonumber()" didn't make a difference (I'm running 4.1.5).. and eventstats destroys the formatting of the output, and it still doesn't show percent_difference. &lt;BR /&gt;
Is it safe to say that the reason it's not working is because it can't do the calculation?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 00:35:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62286#M1375</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-02T00:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62287#M1376</link>
      <description>&lt;P&gt;Okay I think I know what the problem is. I changed the calculation to this for testing purposes:&lt;BR /&gt;
    "| eval percent_difference=(max(listSelect))"&lt;BR /&gt;
I wanted to see if it could at least pick out the higher of the two listSelects. It can't. Instead, it just lists both listSelects values. It's as if the two listSelects are from two separate searches or something...&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 00:43:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62287#M1376</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-02T00:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62288#M1377</link>
      <description>&lt;P&gt;@Branden yes I believe that is pretty safe to say. What about switching max and tonumber? as in eval &lt;CODE&gt;percent_difference=((difference/tonumber(max(listSelect)))*100&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 00:43:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62288#M1377</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-02T00:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62289#M1378</link>
      <description>&lt;P&gt;And I think part of the problem too is that listSelect isn't a number; it doesn't have that 'n' next to the field. I know we tried wrapping it around that tonumber() function, but for some reason it's not taking. &lt;BR /&gt;
(My indexer is running 4.1.5, but the forwarder that is capturing this data is running 4.1.4. The forwarder version shouldn't matter, right?)&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 00:49:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62289#M1378</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-02T00:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62290#M1379</link>
      <description>&lt;P&gt;Forwarder version should not matter.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 00:51:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62290#M1379</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-02T00:51:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62291#M1380</link>
      <description>&lt;P&gt;I think part of the problem is the list() command. It looks like max just doesnt work on its output...&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 00:52:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62291#M1380</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-02T00:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62292#M1381</link>
      <description>&lt;P&gt;Did another answer edit. What about calculating the max(listSelect) via eventstats before the eval? works in my test..&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 00:59:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62292#M1381</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-02T00:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62293#M1382</link>
      <description>&lt;P&gt;GOT IT!&lt;BR /&gt;
I looked closer at the list of fields... and there was a "Select(n)" field there which corresponded to the values in listSelect. I don't know why both were listed, but I don't particularly care at this point. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
Anyways, I plugged in "Select" instead of "listSelect" and it worked beautifully!&lt;BR /&gt;
    | eval percent_difference=((difference/(max(Select)))*100) &lt;/P&gt;

&lt;P&gt;Thank you SO much for your help! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 00:59:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62293#M1382</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-02T00:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62294#M1383</link>
      <description>&lt;P&gt;Your third edit above worked sorta... the only problem is that it took the max(listSelect) of all the indexed results, not just the listSelect for that one entry. (I hope that made sense).&lt;BR /&gt;
Regardless, I think I have the problem fixed now (see comment above). Thanks again, I couldn't have done this with your help and patience.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 01:03:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62294#M1383</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-02T01:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62295#M1384</link>
      <description>&lt;P&gt;I love how your Edit2 formats it though... If I can get it to grab the correct max(listSelect) setting, that would be golden. I'll post my results here when I figure it out. Thanks again!&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 01:10:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62295#M1384</guid>
      <dc:creator>Branden</dc:creator>
      <dc:date>2010-10-02T01:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated the percent difference between two values</title>
      <link>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62296#M1385</link>
      <description>&lt;P&gt;Glad to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Oct 2010 01:12:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Calculated-the-percent-difference-between-two-values/m-p/62296#M1385</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-10-02T01:12:13Z</dc:date>
    </item>
  </channel>
</rss>

