<?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 edit my search to calculate percentage of a multivalued field for total by Country? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254904#M76319</link>
    <description>&lt;P&gt;Almost and perhaps I left out a key piece in my original question (of which I apologize). &lt;/P&gt;

&lt;P&gt;I want to see what the percentage of quarantined messages by country compared to the total amount of messages by country. So for example, we received 100 emails from Canada, of which 10 were quarantined, so 10% of message from Canada are quarantined, and so on for the other countries and then sort from highest to lowest based on percentage.&lt;/P&gt;

&lt;P&gt;Does that help clarify what I'm looking to do?&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
    <pubDate>Thu, 19 May 2016 17:45:50 GMT</pubDate>
    <dc:creator>jwalzerpitt</dc:creator>
    <dc:date>2016-05-19T17:45:50Z</dc:date>
    <item>
      <title>How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254902#M76317</link>
      <description>&lt;P&gt;I'm trying to craft a search that will show the percentage of quarantined messages by country, but I'm struggling a little on how to complete it. I have the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="email" `MACRO` [search sourcetype=csv | iplocation FromIP | stats count by Country | where Country != "United States" | sort 20 -count ] 
| eval success=if(Status="Quarantined",1,0)
| stats count as total sum(success) as success
| eval Percentage=success/total
| table _time Percentage
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I strip out the subsearch, I get the percentage, but trying to figure out how to incorporate iplocation into the search and then break that down per country.&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 17:13:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254902#M76317</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2016-05-19T17:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254903#M76318</link>
      <description>&lt;P&gt;Is this what you're looking for?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   index="email" `MACRO` [search sourcetype=csv | iplocation FromIP | where Country != "United States" |  stats count by FromIP | sort 20 -count | table FromIP ] 
    | eval success=if(Status="Quarantined", 1, 0)
    | iplocation FromIP
    | eventstats count as total by FromIP
    | eval avgper=1/total
    | timechart sum(avgper) as Percentage by Country
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 May 2016 17:35:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254903#M76318</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-05-19T17:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254904#M76319</link>
      <description>&lt;P&gt;Almost and perhaps I left out a key piece in my original question (of which I apologize). &lt;/P&gt;

&lt;P&gt;I want to see what the percentage of quarantined messages by country compared to the total amount of messages by country. So for example, we received 100 emails from Canada, of which 10 were quarantined, so 10% of message from Canada are quarantined, and so on for the other countries and then sort from highest to lowest based on percentage.&lt;/P&gt;

&lt;P&gt;Does that help clarify what I'm looking to do?&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 17:45:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254904#M76319</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2016-05-19T17:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254905#M76320</link>
      <description>&lt;P&gt;Try this change&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     ...
     | eventstats count as total sum(success) as success by FromIP
     | eval perc=success/total
     | timechart max(perc) as Percentage max(total) as Total by Country
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 May 2016 17:59:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254905#M76320</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-05-19T17:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254906#M76321</link>
      <description>&lt;P&gt;Looks much better, but can I replace timechart with stats?&lt;/P&gt;

&lt;P&gt;Thx again&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 18:06:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254906#M76321</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2016-05-19T18:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254907#M76322</link>
      <description>&lt;P&gt;Also to confirm, is this calculating the percentage of quarantined messages by the total number of message per country? The percentages for each country seem to be off.&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 18:15:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254907#M76322</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2016-05-19T18:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254908#M76323</link>
      <description>&lt;P&gt;When you say you want to use stats instead of timechart, does that mean you do not what to see time?  See which of these you prefer&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="email" `MACRO` [search sourcetype=csv | iplocation FromIP | where Country != "United States" |  stats count by FromIP | sort 20 -count | table FromIP ] 
     | iplocation FromIP
     | eventstats count as total count(eval(Status="Quarantined")) as success by FromIP
     | eval avgper=success/total
     | timechart values(avgper) as Percentage by Country

OR 

index="email" `MACRO` [search sourcetype=csv | iplocation FromIP | where Country != "United States" |  stats count by FromIP | sort 20 -count | table FromIP ] 
     | iplocation FromIP
     | stats count as Total count(eval(Status="Quarantined")) as success by Country
     | eval Percentage=success/Total
     | table Country Total Percentage 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 May 2016 18:48:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254908#M76323</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-05-19T18:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254909#M76324</link>
      <description>&lt;P&gt;Correct, I just want to see the table for whatever date/time period I select (for example, past 4 hours).&lt;/P&gt;

&lt;P&gt;I still don't think the percentage calculation is working as what i did was focused on just Canada and did a quick query to produce the percentage of quarantined messages received from Canada (372) vs. the total number of email received from Canada (2444) for a defined 30 minutes period, which is 15%.&lt;/P&gt;

&lt;P&gt;However, when I run the following query:&lt;/P&gt;

&lt;P&gt;index="email" | iplocation FromIP | where Country = "Canada" |  stats count by Country | sort 20 -count&lt;BR /&gt;
      | iplocation FromIP&lt;BR /&gt;
      | stats count as Total count(eval(Status="Quarantined")) as success by Country&lt;BR /&gt;
      | eval Percentage=success/Total&lt;BR /&gt;
      | table Country Total Percentage&lt;/P&gt;

&lt;P&gt;I see the following table:&lt;BR /&gt;
Country          Total          Percentage&lt;BR /&gt;
Canada               1                      0&lt;/P&gt;

&lt;P&gt;I would expect to see 15% for percentage&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 19:08:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254909#M76324</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2016-05-19T19:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254910#M76325</link>
      <description>&lt;P&gt;Changed the query to:&lt;/P&gt;

&lt;P&gt;index="email" | iplocation FromIP | where Country = "Canada" |  stats count by Country | sort 20 -count&lt;BR /&gt;
| eventstats count as Total, count(eval(Status="Quarantined")) as success by Country&lt;BR /&gt;
| eval Percentage=success/Total&lt;/P&gt;

&lt;P&gt;and now I'm seeing the count of 2,444 emails received, but the Total is 1 and no percentage. Seems to have an issue with - count(eval(Status="Quarantined")) as success by Country&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 19:12:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254910#M76325</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2016-05-19T19:12:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254911#M76326</link>
      <description>&lt;P&gt;Did you try changing it to the way you had it &lt;CODE&gt;sum(eval(if(Status="Quarantined", 1, 0)))&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 19:49:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254911#M76326</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-05-19T19:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254912#M76327</link>
      <description>&lt;P&gt;Much better as the query now reads:&lt;/P&gt;

&lt;P&gt;index="email" | iplocation FromIP | where Country = "Canada"&lt;BR /&gt;
| eventstats count as TotalCount, sum(eval(if(Status="Quarantined", 1, 0))) AS Caught by Country &lt;BR /&gt;
| eval Percentage=(Caught/TotalCount)*100&lt;BR /&gt;
| table Country Percentage&lt;/P&gt;

&lt;P&gt;but I'm seeing the percentage for each event (all 2,444 of them) instead of one event&lt;/P&gt;

&lt;P&gt;Thx&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 19:56:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254912#M76327</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2016-05-19T19:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254913#M76328</link>
      <description>&lt;P&gt;Changed from eventstats to stats and good to go now:&lt;/P&gt;

&lt;P&gt;index="email" | iplocation FromIP | where Country = "Canada"&lt;BR /&gt;
| stats count as TotalCount, sum(eval(if(Status="Quarantined", 1, 0))) AS Caught by Country &lt;BR /&gt;
| eval Percentage=(Caught/TotalCount)*100&lt;BR /&gt;
| table Country Percentage&lt;/P&gt;

&lt;P&gt;as I see one line showing Canada at 15.22%. &lt;/P&gt;

&lt;P&gt;Thx for helping me work through this! Greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 20:37:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254913#M76328</guid>
      <dc:creator>jwalzerpitt</dc:creator>
      <dc:date>2016-05-19T20:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to calculate percentage of a multivalued field for total by Country?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254914#M76329</link>
      <description>&lt;P&gt;If this worked, please mark as answered for others who may have similar requirements. &lt;/P&gt;</description>
      <pubDate>Thu, 19 May 2016 20:41:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-calculate-percentage-of-a-multivalued/m-p/254914#M76329</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-05-19T20:41:40Z</dc:date>
    </item>
  </channel>
</rss>

