<?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: Calculating percentages based on counts in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculating-percentages-based-on-counts/m-p/403592#M116771</link>
    <description>&lt;P&gt;@hduncan7 ,&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by Table | addcoltotals labelfield="Table"| eval _Total=if(Table=="Total",count,0)
| eventstats sum(_Total) as _Total| eval percentage=(count/_Total)*100
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 04 Jun 2019 17:03:40 GMT</pubDate>
    <dc:creator>renjith_nair</dc:creator>
    <dc:date>2019-06-04T17:03:40Z</dc:date>
    <item>
      <title>Calculating percentages based on counts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-percentages-based-on-counts/m-p/403590#M116769</link>
      <description>&lt;P&gt;I'm trying to get percentages based on the number of logs per table. I want the results to look like this:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Table                   Count                    Percentage&lt;/STRONG&gt;&lt;BR /&gt;
Total                        14392                    100&lt;BR /&gt;
TBL1                          8302                     57.68&lt;BR /&gt;
TBL2                          4293                     29.93&lt;BR /&gt;
TBL3                            838                     5.82&lt;BR /&gt;
TBL4                            639                     4.44&lt;BR /&gt;
TBL5                            320                     2.22&lt;/P&gt;

&lt;P&gt;Here's my search so far:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;text = "\*" (TBL1 OR TBL2 OR TBL3 OR TBL4 OR TBL5) | eventstats count AS Total
| append [search PAJYE text = "\*TBL1\*" | stats count | eval "Count Type" = "TBL1 Count" | eval "Percentage" = ((count/Total)\*100)]
| append [search PAJYE text = "\*TBL2\*" | stats count | eval "Count Type" = "TBL2 Count" | eval "Percentage" = ((count/Total)\*100)] 
| append [search PAJYE text = "\*TBL3\*" | stats count | eval "Count Type" = "TBL3 Count" | eval "Percentage" = ((count/Total)\*100)] 
| append [search PAJYE text = "\*TBL4\*" | stats count | eval "Count Type" = "TBL4 Count" | eval "Percentage" = ((count/Total)\*100)] 
| append [search PAJYE text = "\*TBL5\*" | stats count | eval "Count Type" = "TBL5 Count" | eval "Percentage" = ((count/Total)\*100)]
| append [search PAJYE text = "\*" (TBL1 OR TBL2 OR TBL3 OR TBL4 OR TBL5) | stats count | eval "Count Type" = "Total Count" | eval "Percentage" = ((count/Total)\*100)]
| rename count as "Count"
| sort - "Count"
| table "Count Type", "Count", "Percentage"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've tried so many different methods of trying to get this to work. My results are either a percentage column with no data, the counts get messed up, or pages of empty rows following my data.&lt;/P&gt;

&lt;P&gt;Any help would be appreciated. &lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 13:10:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-percentages-based-on-counts/m-p/403590#M116769</guid>
      <dc:creator>hduncan7</dc:creator>
      <dc:date>2019-06-04T13:10:44Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentages based on counts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-percentages-based-on-counts/m-p/403591#M116770</link>
      <description>&lt;P&gt;I would extract the Table name as a field if you haven't already, the try something like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(tablename=TBL1 OR tablename=TBL2 OR tablename=TBL3)
| eventstats count as totalevents 
| eventstats count as tablecount by tablename 
| eval percentage=(tablecount/totalevents)*100 
| stats values(tablecount) as totalevents values(percentage) as table_perc by tablename
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I only covered 3 of the tablenames, but you get the idea.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 15:15:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-percentages-based-on-counts/m-p/403591#M116770</guid>
      <dc:creator>kmorris_splunk</dc:creator>
      <dc:date>2019-06-04T15:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentages based on counts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-percentages-based-on-counts/m-p/403592#M116771</link>
      <description>&lt;P&gt;@hduncan7 ,&lt;/P&gt;

&lt;P&gt;Try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count by Table | addcoltotals labelfield="Table"| eval _Total=if(Table=="Total",count,0)
| eventstats sum(_Total) as _Total| eval percentage=(count/_Total)*100
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 04 Jun 2019 17:03:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-percentages-based-on-counts/m-p/403592#M116771</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-06-04T17:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating percentages based on counts</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-percentages-based-on-counts/m-p/403593#M116772</link>
      <description>&lt;P&gt;This is basically what I ended up doing. I found a solution but forgot to update my question. &lt;/P&gt;

&lt;P&gt;My solution&lt;BR /&gt;
     text = "*TBL1*" | eval "Table Name" = "TBL1"&lt;BR /&gt;
    | append [search text = "*TBL2*" | eval "Table Name" = "TBL2"] &lt;BR /&gt;
    | append [search text = "*TBL3*" | eval "Table Name" = "TBL3"] &lt;BR /&gt;
    | append [search text = "*TBL4*" | eval "Table Name" = "TBL4"]&lt;BR /&gt;
    | append [search text = "*TBL5*" | eval "Table Name" = "TBL5"]&lt;BR /&gt;
    | append [search text = "*" (TBL1 OR TBL2 OR TBL3 OR TBL4 OR TBL5) | eval "Table Name" = "Total"]&lt;BR /&gt;
    | table "Table Name"&lt;BR /&gt;
    | eventstats count as "totalCount" | eventstats count as "tblCount" by "Table Name" | eval percent = round((tblCount/totalCount)*200,2) | stats values(tblCount) as Count, values(percent) as Percentage by "Table Name" | sort - Count&lt;/P&gt;

&lt;P&gt;My percentage is multiplied by 200 to account for the fact that I'm finding the total count as well.&lt;/P&gt;

&lt;P&gt;Thanks for your help kmorris&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jun 2019 17:14:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-percentages-based-on-counts/m-p/403593#M116772</guid>
      <dc:creator>hduncan7</dc:creator>
      <dc:date>2019-06-04T17:14:55Z</dc:date>
    </item>
  </channel>
</rss>

