<?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 Finding a percentage for every value in another field in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Finding-a-percentage-for-every-value-in-another-field/m-p/308390#M92504</link>
    <description>&lt;P&gt;I am looking for source IPs that have a high percentage of being blocked. The evaluations below work fine if I use just one source IP. But I want to test multiple source IPs, and am not sure how to cycle through them. I know that Splunk has a foreach command. I am not sure how to cycle the testing SPL into the 'foreach loop'. (Or how to refer to the src variable for purposes of getting a total count.)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Network_Search&amp;gt;  (src="1.1.1.1" OR src="1.1.1.2")
| stats count(eval(src="")) as totalCount,count(eval(result="blocked")) as blocked
| eval blockedPercent=blocked/totalCount*100
| where blockedPercent&amp;gt;50
| table src, blockedPercent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Anyone good at nesting this type of search?&lt;/P&gt;

&lt;P&gt;I did find:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/298931/how-to-calculate-percentage-for-each-category.html"&gt;https://answers.splunk.com/answers/298931/how-to-calculate-percentage-for-each-category.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;But when I use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Network_Search&amp;gt;  (src="1.1.1.1" OR src="1.1.1.2")
| eventstats count(src) as total |stats count(eval(result="blocked")) as count by src |eval percent=round(count/total*100,2) 
| table src,percent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get a blank percentage. Not sure if I should stick with event stats, or try a foreach...&lt;/P&gt;</description>
    <pubDate>Sun, 02 Apr 2017 01:14:43 GMT</pubDate>
    <dc:creator>stakor</dc:creator>
    <dc:date>2017-04-02T01:14:43Z</dc:date>
    <item>
      <title>Finding a percentage for every value in another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-a-percentage-for-every-value-in-another-field/m-p/308390#M92504</link>
      <description>&lt;P&gt;I am looking for source IPs that have a high percentage of being blocked. The evaluations below work fine if I use just one source IP. But I want to test multiple source IPs, and am not sure how to cycle through them. I know that Splunk has a foreach command. I am not sure how to cycle the testing SPL into the 'foreach loop'. (Or how to refer to the src variable for purposes of getting a total count.)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Network_Search&amp;gt;  (src="1.1.1.1" OR src="1.1.1.2")
| stats count(eval(src="")) as totalCount,count(eval(result="blocked")) as blocked
| eval blockedPercent=blocked/totalCount*100
| where blockedPercent&amp;gt;50
| table src, blockedPercent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Anyone good at nesting this type of search?&lt;/P&gt;

&lt;P&gt;I did find:&lt;BR /&gt;
&lt;A href="https://answers.splunk.com/answers/298931/how-to-calculate-percentage-for-each-category.html"&gt;https://answers.splunk.com/answers/298931/how-to-calculate-percentage-for-each-category.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;But when I use:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Network_Search&amp;gt;  (src="1.1.1.1" OR src="1.1.1.2")
| eventstats count(src) as total |stats count(eval(result="blocked")) as count by src |eval percent=round(count/total*100,2) 
| table src,percent
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get a blank percentage. Not sure if I should stick with event stats, or try a foreach...&lt;/P&gt;</description>
      <pubDate>Sun, 02 Apr 2017 01:14:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-a-percentage-for-every-value-in-another-field/m-p/308390#M92504</guid>
      <dc:creator>stakor</dc:creator>
      <dc:date>2017-04-02T01:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding a percentage for every value in another field</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-a-percentage-for-every-value-in-another-field/m-p/308391#M92505</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;Network_Search&amp;gt;
| stats count AS totalCount count(eval(result="blocked")) AS blockedCount BY src
| eval blockedPercent=round(100*blockedCount/totalCount, 2)
| search blockedPercent&amp;gt;50
| table src, blockedPercent
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 02 Apr 2017 02:33:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-a-percentage-for-every-value-in-another-field/m-p/308391#M92505</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-02T02:33:42Z</dc:date>
    </item>
  </channel>
</rss>

