<?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 Stats count as a percentage as the total? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100957#M26079</link>
    <description>&lt;P&gt;I have a search which I am using stats to generate a data grid. Something to the affect of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Choice1 10
Choice2 50
Choice3 100
Choice4 40
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would now like to add a third column that is the percentage of the overall count. So something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Choice1 10 .05
Choice2 50 .25
Choice3 100 .50
Choice4 40  .20
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suspect I need to use a subsearch for this because each row now depends on the total count but I am not exactly sure how to accomplish this. Any help would be greatly appreciated.&lt;/P&gt;</description>
    <pubDate>Sat, 29 Oct 2022 00:20:15 GMT</pubDate>
    <dc:creator>christopherutz</dc:creator>
    <dc:date>2022-10-29T00:20:15Z</dc:date>
    <item>
      <title>Stats count as a percentage as the total?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100957#M26079</link>
      <description>&lt;P&gt;I have a search which I am using stats to generate a data grid. Something to the affect of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Choice1 10
Choice2 50
Choice3 100
Choice4 40
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would now like to add a third column that is the percentage of the overall count. So something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE&gt;Choice1 10 .05
Choice2 50 .25
Choice3 100 .50
Choice4 40  .20
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I suspect I need to use a subsearch for this because each row now depends on the total count but I am not exactly sure how to accomplish this. Any help would be greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Sat, 29 Oct 2022 00:20:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100957#M26079</guid>
      <dc:creator>christopherutz</dc:creator>
      <dc:date>2022-10-29T00:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count as a percentage as the total</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100958#M26080</link>
      <description>&lt;P&gt;You can do this without a subsearch - take a look at the &lt;A href="http://www.splunk.com/base/Documentation/latest/SearchReference/Eventstats" rel="nofollow"&gt;&lt;CODE&gt;eventstats&lt;/CODE&gt;&lt;/A&gt;  command.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2010 04:59:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100958#M26080</guid>
      <dc:creator>southeringtonp</dc:creator>
      <dc:date>2010-12-08T04:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count as a percentage as the total</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100959#M26081</link>
      <description>&lt;P&gt;Thanks, this is exactly what I needed.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2010 06:18:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100959#M26081</guid>
      <dc:creator>christopherutz</dc:creator>
      <dc:date>2010-12-08T06:18:27Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count as a percentage as the total</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100960#M26082</link>
      <description>&lt;P&gt;Maybe I am being dense, but the eventstats documentation is baffling and I cannot get it to calculate percentages as asked in the question.&lt;/P&gt;

&lt;P&gt;Any chance of a worked example?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2011 15:40:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100960#M26082</guid>
      <dc:creator>raoul</dc:creator>
      <dc:date>2011-08-18T15:40:37Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count as a percentage as the total</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100961#M26083</link>
      <description>&lt;P&gt;For the earlier question, you could probably do something like this:    &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eventstats count as "totalCount" | eventstats count as "choiceCount" by choice  | eval percent=(choiceCount/totalCount)*100 | stats values(choiceCount), values(percent) by choice
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Usually, you can avoid eventstats altogether and just use the "top" command (&lt;A href="http://docs.splunk.com/Documentation/Splunk/4.2.3/SearchReference/Top"&gt;http://docs.splunk.com/Documentation/Splunk/4.2.3/SearchReference/Top&lt;/A&gt; ) like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | top choice limit=0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2011 21:23:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/100961#M26083</guid>
      <dc:creator>acdevlin</dc:creator>
      <dc:date>2011-08-18T21:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count as a percentage as the total</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/544259#M154167</link>
      <description>&lt;P&gt;In addition to this, in order to avoid using multiple stats stanzas, I use this type of structure with a stats then an eval:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| search (message="Polling" OR message="No data" OR message="503" OR message="Pushing") 
| timechart count(eval(message="Polling")) as Total_Polls count(eval(message="No data")) as Dataless_Polls count(eval(message="503")) as Error_Polls count(eval(message="Pushing")) as Successful_Polls 
| eval Percent_Successful=(((Successful_Polls)/Total_Polls)*100) 
| fields _time Percent_Successful&lt;/LI-CODE&gt;&lt;P&gt;This allows you to just compute one stats function and then evaluate any combination of percentages across your dataset. Of course this is a timechart, so you can just replace this with stats to get the desired functionality.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Mar 2021 20:39:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/544259#M154167</guid>
      <dc:creator>haraksin</dc:creator>
      <dc:date>2021-03-17T20:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Stats count as a percentage as the total</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/618805#M215062</link>
      <description>&lt;P&gt;The&amp;nbsp; "top" example worked for me instead. eventstats didn't make sense&lt;/P&gt;</description>
      <pubDate>Fri, 28 Oct 2022 22:19:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-count-as-a-percentage-as-the-total/m-p/618805#M215062</guid>
      <dc:creator>klaurea</dc:creator>
      <dc:date>2022-10-28T22:19:18Z</dc:date>
    </item>
  </channel>
</rss>

