<?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: Is there a faster way to calculate percentages faster? in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/Is-there-a-faster-way-to-calculate-percentages-faster/m-p/558215#M9278</link>
    <description>&lt;P&gt;The top command does just that&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval CITY="Boston;Sydney;London;Cairo;Paris;Rome;Casablanca;Vancouver;San Francisco;Munich;Berlin;Helsinki" 
| eval CITY=split(CITY,";") 
| mvexpand CITY 
| eval n=mvrange(1,random() % 10 + 1)
| mvexpand n
| eval COMMENT="UP TO HERE PRODUCES EXAMPLE DATA"
| top 0 CITY&lt;/LI-CODE&gt;&lt;P&gt;As for whether this is faster than doing eventstats the calculating percentages, I am not sure, but it's certainly less code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jul 2021 23:49:56 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2021-07-02T23:49:56Z</dc:date>
    <item>
      <title>Is there a faster way to calculate percentages faster?</title>
      <link>https://community.splunk.com/t5/Reporting/Is-there-a-faster-way-to-calculate-percentages-faster/m-p/558193#M9276</link>
      <description>&lt;P&gt;Well Hello Gorgeous people!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a fields that can take anywhere from 3 to 5 diferente values which are cities... this field is called "CITY" if I want to get the percentage of each city over the total count I always Have to do something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats count(eval(CITY="A")) as CITY_A, count(eval(CITY="B")) as CITY_B, count(eval(CITY="C")) as CITY_C, count(CITY) as TOTAL
| eval %P_CITY_A=CITY_A/TOTAL (repeat for each city)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;but often times I find myself wanting to calculate percetages of the values of fields that can have up to 15 differente values.. and I just wonder is there is a faster more effcient way of doing this.... thank you so much people&lt;BR /&gt;&lt;BR /&gt;love,&lt;/P&gt;&lt;P&gt;cindy&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 18:28:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Is-there-a-faster-way-to-calculate-percentages-faster/m-p/558193#M9276</guid>
      <dc:creator>cindygibbs_08</dc:creator>
      <dc:date>2021-07-02T18:28:51Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to calculate percentages faster?</title>
      <link>https://community.splunk.com/t5/Reporting/Is-there-a-faster-way-to-calculate-percentages-faster/m-p/558207#M9277</link>
      <description>&lt;P&gt;At first I thought about using FOREACH, but I'm sure the real city names don't all start with "CITY_" so that won't work.&lt;/P&gt;&lt;P&gt;This does work, however, but it's a little ugly.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval CITY="Boston;Sydney;London;Boston;Paris;Cairo;Paris;London" 
| eval CITY=split(CITY,";") 
| mvexpand CITY 
```Everything above sets up test data.  Don't use in the real query```
```Get counts for each city```
| stats count by CITY 
```Get the total count and assign it to bogus city "A" (don't change that)```
```Get the total count and add it as a field to each row```
| eventstats sum(count) as TOTAL
```Compute the percentage```
| eval PCT=count*100/TOTAL 
```Remove the TOTAL field (optional)```
| fields - TOTAL&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 02 Jul 2021 20:22:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Is-there-a-faster-way-to-calculate-percentages-faster/m-p/558207#M9277</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-07-02T20:22:11Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a faster way to calculate percentages faster?</title>
      <link>https://community.splunk.com/t5/Reporting/Is-there-a-faster-way-to-calculate-percentages-faster/m-p/558215#M9278</link>
      <description>&lt;P&gt;The top command does just that&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults 
| eval CITY="Boston;Sydney;London;Cairo;Paris;Rome;Casablanca;Vancouver;San Francisco;Munich;Berlin;Helsinki" 
| eval CITY=split(CITY,";") 
| mvexpand CITY 
| eval n=mvrange(1,random() % 10 + 1)
| mvexpand n
| eval COMMENT="UP TO HERE PRODUCES EXAMPLE DATA"
| top 0 CITY&lt;/LI-CODE&gt;&lt;P&gt;As for whether this is faster than doing eventstats the calculating percentages, I am not sure, but it's certainly less code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jul 2021 23:49:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Is-there-a-faster-way-to-calculate-percentages-faster/m-p/558215#M9278</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2021-07-02T23:49:56Z</dc:date>
    </item>
  </channel>
</rss>

