<?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 find percentage with selective sum of field values? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628223#M218235</link>
    <description>&lt;P&gt;yeah,&amp;nbsp; right. modified it. thanks&lt;BR /&gt;&lt;SPAN&gt;226 / (2924 + 226) = 7.17%&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Jan 2023 06:16:22 GMT</pubDate>
    <dc:creator>vinothkumark</dc:creator>
    <dc:date>2023-01-25T06:16:22Z</dc:date>
    <item>
      <title>How to find percentage with selective sum of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628189#M218218</link>
      <description>&lt;P&gt;&amp;lt; query &amp;gt; ... | stats count by return_code fetches me the below output.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vinothkumark_0-1674585802845.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23521i0F79A39194C710F7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vinothkumark_0-1674585802845.png" alt="vinothkumark_0-1674585802845.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have to create an alert where the &lt;STRONG&gt;sum&lt;/STRONG&gt; of any return_code value other than 100 and 200 should not cross 20% of the overall value.&lt;BR /&gt;&lt;BR /&gt;Example: from the above image, I will add the count of return_codes (other than 100 and 200 ) which will result as 226. now the count of 100 and 200 is 2924. now the&amp;nbsp; percentage will come around 7.17 %.&lt;BR /&gt;How do I achieve this via query?&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 06:15:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628189#M218218</guid>
      <dc:creator>vinothkumark</dc:creator>
      <dc:date>2023-01-25T06:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: how to find percentage with selective sum of field values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628193#M218220</link>
      <description>&lt;P&gt;From the current results, use eventstats to compute the subtotals by return_code.&amp;nbsp; Then you can calculate the percentage.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;.. | stats count by return_code
| eventstats sum(eval(return_code&amp;lt;=200)) as OK, sum(eval(return_code&amp;gt;200)) as KO
| eval pctKO = (KO * 100) / OK&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 24 Jan 2023 19:01:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628193#M218220</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-01-24T19:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to find percentage with selective sum of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628210#M218230</link>
      <description>&lt;P&gt;Just a technical comment on the maths...&lt;/P&gt;&lt;P&gt;When you say that ...&lt;STRONG&gt;&lt;SPAN&gt;should not cross 20% of the overall value.&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;your calculation of 7.7% indicates that failures is compared only against successes (100+200), i.e 226/2924, however, if you want it to be of 'overall value' then the formula would be&lt;/P&gt;&lt;P&gt;226 / (2924 + 226) = 7.17%&lt;/P&gt;&lt;P&gt;and&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/213957"&gt;@richgalloway&lt;/a&gt;&amp;nbsp;formula would be&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval pctKO = (KO * 100) / (OK + KO)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 21:46:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628210#M218230</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-01-24T21:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to find percentage with selective sum of field values?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628223#M218235</link>
      <description>&lt;P&gt;yeah,&amp;nbsp; right. modified it. thanks&lt;BR /&gt;&lt;SPAN&gt;226 / (2924 + 226) = 7.17%&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 06:16:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628223#M218235</guid>
      <dc:creator>vinothkumark</dc:creator>
      <dc:date>2023-01-25T06:16:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to find percentage with selective sum of field values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628227#M218236</link>
      <description>&lt;P&gt;Sorry I think I didn't put it in the right way.&amp;nbsp;&lt;BR /&gt;It calculates the return_code like below ( check KO and OK )&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vinothkumark_1-1674627569909.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23525iBD97DFE5FA5E6AD0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vinothkumark_1-1674627569909.png" alt="vinothkumark_1-1674627569909.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But I want to calculate the highlighted ones.&amp;nbsp;&lt;BR /&gt;Example: 8+9+3 = 20&lt;BR /&gt;254 + 227 = 481&lt;BR /&gt;perc = 20*100/(20+481)=3.1%&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jan 2023 06:24:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628227#M218236</guid>
      <dc:creator>vinothkumark</dc:creator>
      <dc:date>2023-01-25T06:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to find percentage with selective sum of field values</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628229#M218237</link>
      <description>&lt;P&gt;The eventstats should be&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eventstats sum(eval(if(return_code&amp;lt;=200, count, 0))) as OK, sum(eval(if(return_code&amp;gt;200, count, 0))) as KO
| eval pctKO = (KO * 100) / (OK + KO)&lt;/LI-CODE&gt;&lt;P&gt;however, with your calculations this actually is 3.99%...&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| eval x=split("100:254,200:227,404:8,404:3,406:9", ",")
| mvexpand x
| rex field=x "(?&amp;lt;return_code&amp;gt;\d+):(?&amp;lt;count&amp;gt;\d+)"
| table return_code count
| eventstats sum(eval(if(return_code&amp;lt;=200, count, 0))) as OK, sum(eval(if(return_code&amp;gt;200, count, 0))) as KO
| eval pctKO = (KO * 100) / (OK + KO)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 25 Jan 2023 06:39:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-find-percentage-with-selective-sum-of-field-values/m-p/628229#M218237</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-01-25T06:39:29Z</dc:date>
    </item>
  </channel>
</rss>

