<?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 calculate percentages with multiple count function in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565630#M197085</link>
    <description>&lt;P&gt;I tried your method, but it doesn't seem to work to use two count function in the same search.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Sep 2021 08:27:32 GMT</pubDate>
    <dc:creator>homer07</dc:creator>
    <dc:date>2021-09-02T08:27:32Z</dc:date>
    <item>
      <title>How to calculate percentages with multiple count function？</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565623#M197079</link>
      <description>&lt;P&gt;I'm trying to calculate percentages based on the number of events per vary group. There are actually a lot of events, so can't use method like count(eval(...)). The summary of&amp;nbsp;events is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;color
------
green
red
greed
greed
red&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here's my search so far:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="test" sourcetype="csv"
| stats count as numColor by color
| eval total=5 
| eval percent=printf("%.2f", (numColor/total)*100)
| sort num(percent)
| table color numColor percent&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I replace the hardcore variable value "total" with count() function or other methods?&lt;BR /&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 08:33:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565623#M197079</guid>
      <dc:creator>homer07</dc:creator>
      <dc:date>2021-09-02T08:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate percentages with multiple count function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565624#M197080</link>
      <description>&lt;P&gt;There is probably another way. But I'd do your initial search&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index="test" sourcetype="csv"
| stats count as numColor by color&lt;/LI-CODE&gt;&lt;P&gt;Then I'd add eventstats to have sum of the counts in every row&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|eventstats sum(count) as totalcolors&lt;/LI-CODE&gt;&lt;P&gt;So now you can simply evaluate&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval percentage=numColor/totalcolors&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 02 Sep 2021 08:04:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565624#M197080</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-09-02T08:04:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate percentages with multiple count function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565630#M197085</link>
      <description>&lt;P&gt;I tried your method, but it doesn't seem to work to use two count function in the same search.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 08:27:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565630#M197085</guid>
      <dc:creator>homer07</dc:creator>
      <dc:date>2021-09-02T08:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate percentages with multiple count function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565636#M197091</link>
      <description>&lt;P&gt;Sorry, my mistake. sum(numColor), not sum(count). You renamed the column in your stats.&lt;/P&gt;&lt;PRE&gt;| makeresults &lt;BR /&gt;| eval _raw="red&lt;BR /&gt;green&lt;BR /&gt;red&lt;BR /&gt;blue&lt;BR /&gt;green&lt;BR /&gt;red&lt;BR /&gt;red&lt;BR /&gt;green" &lt;BR /&gt;| multikv noheader=t&lt;BR /&gt;| table Column_1 &lt;BR /&gt;| rename Column_1 as color| stats count as numColor by color |eventstats sum(numColor) as totalcolors &lt;BR /&gt;| eval percentage=numColor/totalcolors &lt;BR /&gt;| fields - totalcolors&lt;BR /&gt;| fieldformat percentage=round(percentage*100,1)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PickleRick_1-1630579139949.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/15815iB7B9EE4CD593DC48/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PickleRick_1-1630579139949.png" alt="PickleRick_1-1630579139949.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 10:39:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565636#M197091</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-09-02T10:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate percentages with multiple count function</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565653#M197102</link>
      <description>&lt;P&gt;Thanks, it's great!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Sep 2021 10:46:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-percentages-with-multiple-count-function/m-p/565653#M197102</guid>
      <dc:creator>homer07</dc:creator>
      <dc:date>2021-09-02T10:46:40Z</dc:date>
    </item>
  </channel>
</rss>

