<?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: Convert a table to a percent table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220402#M64764</link>
    <description>&lt;P&gt;Bleh I'm tried of monkeying with the formatting to have the bullet list items show up correctly &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Nov 2015 15:20:47 GMT</pubDate>
    <dc:creator>Runals</dc:creator>
    <dc:date>2015-11-06T15:20:47Z</dc:date>
    <item>
      <title>Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220394#M64756</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I have a table that looks like this :&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/798i76FCD95EF85B7B2A/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;And I wish to convert all the values in the table to percent of the line total. Anybody has any idea how that can be done ? What I'm looking for is a table with percentages only, no real values.&lt;/P&gt;

&lt;P&gt;Thanks splunkers.&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
David&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 13:31:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220394#M64756</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2015-11-06T13:31:16Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220395#M64757</link>
      <description>&lt;P&gt;This should get you started.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;your current search&amp;gt; | eval TOTAL=BIND+CONNEXION+NULL+OTHER | eval BIND=round((BIND*100)/TOTAL,2)."%" | eval CONNEXION=round((CONNEXION*100)/TOTAL,2)."%" | eval NULL=round((NULL*100)/TOTAL,2)."%" | eval OTHER=round((OTHER*100)/TOTAL,2)."%" | ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Nov 2015 13:57:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220395#M64757</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-11-06T13:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220396#M64758</link>
      <description>&lt;P&gt;Yeah that should work! thanks mate &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 14:01:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220396#M64758</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2015-11-06T14:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220397#M64759</link>
      <description>&lt;P&gt;If it does, please accept the answer.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 14:04:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220397#M64759</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-11-06T14:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220398#M64760</link>
      <description>&lt;P&gt;It works quite well. Only problem is that in my real table I have way more columns and I would like to automate the eval process so I won't have to write down everything column by column and repeat the eval several times. Any idea how that can be done ? Is the only way to do this by manually including all the column names ?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 14:11:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220398#M64760</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2015-11-06T14:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220399#M64761</link>
      <description>&lt;P&gt;The &lt;CODE&gt;addcoltotals&lt;/CODE&gt; or &lt;CODE&gt;addtotals&lt;/CODE&gt; command may be able to calculate TOTAL automatically, but you'll still have to convert the columns to percentages manually.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 14:22:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220399#M64761</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2015-11-06T14:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220400#M64762</link>
      <description>&lt;P&gt;yeah i figured as much.. thank you Rich &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 14:29:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220400#M64762</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2015-11-06T14:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220401#M64763</link>
      <description>&lt;P&gt;I'd do something like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | addtotals | foreach * [ eval perc&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; = round(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;/Total*100,1) ] | table _time perc* | sort -_time | fields - percTotal
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will dynamically account for any of your display fields. It also didn't seem like you wanted the total events field in the results but you could easily add that within the table command. A couple things to keep in mind:&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;&lt;P&gt;If you add the % sign in the eval you wont be able to sort the results numerically by each column. As you have a time element that is perhaps not desired. However if you want to sort prior to the results being displayed you could adjust the sort field and then after that add another foreach command ie&lt;/P&gt;

&lt;P&gt;| foreach perc* [ eval &amp;lt;&lt;FIELD&gt;&amp;gt; = &amp;lt;&lt;FIELD&gt;&amp;gt; . " %"&lt;/FIELD&gt;&lt;/FIELD&gt;&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;If your fields have any special characters in them the foreach command breaks as written (which drives me crazy). You would need to add single quotes around the FIELD bit like &lt;CODE&gt;round('&amp;lt;&amp;gt;' /Total ...&lt;/CODE&gt;&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Note in my foreach eval I'm making new fields that are like percBIND and percOTHER. You could just as easily not make new fields by changing &lt;CODE&gt;perc&amp;lt;&amp;gt;&lt;/CODE&gt; to just &lt;CODE&gt;[ eval &amp;lt;&amp;gt; =&lt;/CODE&gt; &lt;/P&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 06 Nov 2015 15:16:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220401#M64763</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2015-11-06T15:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220402#M64764</link>
      <description>&lt;P&gt;Bleh I'm tried of monkeying with the formatting to have the bullet list items show up correctly &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 15:20:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220402#M64764</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2015-11-06T15:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220403#M64765</link>
      <description>&lt;P&gt;pretty neat trick, thank you Runals ^^ any good links that explain that foreach command ?&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 15:30:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220403#M64765</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2015-11-06T15:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220404#M64766</link>
      <description>&lt;P&gt;Here is a link to all search commands which I have bookmarked. Once there you can navigate to each command easily enough.&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ListOfSearchCommands"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/ListOfSearchCommands&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I have often wished foreach would work with the fieldformat command which would allow you to add something like your % sign but keep the results an int under the covers but it "only" works with eval. Obviously eval is very powerful. The only other real issue I've run into is if the fields have a special character like "." or ":" which is why I included the bit about adding the single quotes in my answer (which solves for that issue). Being able to list fields makes it run faster than a wildcard pulling in all fields but sometimes I have to use that as there isn't a way to have it run over all fields EXCEPT this field, that field, etc.&lt;/P&gt;

&lt;P&gt;At any rate as with all commands you can over use foreach but it is incredibly handy.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 15:42:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220404#M64766</guid>
      <dc:creator>Runals</dc:creator>
      <dc:date>2015-11-06T15:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert a table to a percent table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220405#M64767</link>
      <description>&lt;P&gt;Thank you for your time and your detailed explanation! &lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 08:45:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Convert-a-table-to-a-percent-table/m-p/220405#M64767</guid>
      <dc:creator>DavidHourani</dc:creator>
      <dc:date>2015-11-09T08:45:09Z</dc:date>
    </item>
  </channel>
</rss>

