<?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: calculate percentage of multiple columns and then create a chart in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/calculate-percentage-of-multiple-columns-and-then-create-a-chart/m-p/432186#M123482</link>
    <description>&lt;P&gt;Thank you so much niketnilay! This is giving me what I need. I was playing around with foreach function before but I was not doing it right. Now i know &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; Really appreciate your help! &lt;/P&gt;</description>
    <pubDate>Fri, 01 Jun 2018 20:16:47 GMT</pubDate>
    <dc:creator>mmdacutanan</dc:creator>
    <dc:date>2018-06-01T20:16:47Z</dc:date>
    <item>
      <title>calculate percentage of multiple columns and then create a chart</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-percentage-of-multiple-columns-and-then-create-a-chart/m-p/432184#M123480</link>
      <description>&lt;P&gt;I have a query (pasted below) that counts occurrence of different strings within the same field called Variable10. I then count the occurrence of that string found in Variable10 and I give it a new name:&lt;/P&gt;

&lt;P&gt;index=uc sourcetype=uc_tcd DigitsDialed=12345 Code!=000000| where not like (Variable7,"%PRE%")|dedup Variable2| timechart span=15m&lt;BR /&gt;
count(eval(like(Variable10,"%|T%"))) as T_Count,&lt;BR /&gt;
count(eval(like(Variable10,"%|M%"))) as M_Count,&lt;BR /&gt;
count(eval(like(Variable10,"%|E%"))) as E_Count,&lt;BR /&gt;
count(eval(like(Variable10,"%|G%"))) as G_Count,&lt;BR /&gt;
count(eval(like(Variable10,"%|P%"))) as P_Count,&lt;BR /&gt;
count(eval(like(Variable10,"%|L%"))) as L_Count,&lt;BR /&gt;
count(eval(like(Variable10,"%346%") OR like(Variable10,"%347%") )) as U_Count,&lt;BR /&gt;
count(eval(not like(Variable10,"%346%") OR not like(Variable10,"%347%")  OR not like(Variable10,"%|T%") OR not like(Variable10,"%|M%") OR not like(Variable10,"%|E%") OR not like(Variable10,"%|G%") OR&lt;BR /&gt;
not like(Variable10,"%|P%") OR not like(Variable10,"%|L%"))) as X_Count&lt;BR /&gt;
| addtotals col=f&lt;/P&gt;

&lt;P&gt;The output looks like this:&lt;/P&gt;

&lt;P&gt;_time                                           T_Count M_Count  E_Count    G_Count     P_Count   L_Count   U_Count     X_Count Total&lt;BR /&gt;
2018-05-30T00:00:00.000-0700    0           0                13                 19                  16            27                    0                   287          362&lt;BR /&gt;
2018-05-30T00:15:00.000-0700    0           0              8                    9                   9             3                 0                   228          257&lt;BR /&gt;
2018-05-30T00:30:00.000-0700    0           0              6                    4                   17            1                 0                   217          245&lt;BR /&gt;
2018-05-30T00:45:00.000-0700    0           0              8                   7                    28            0                 0                   186          229&lt;BR /&gt;
2018-05-30T01:00:00.000-0700    0           0              3                    6                   21            0                 0                   171          201&lt;/P&gt;

&lt;P&gt;What I need now is to be able to calculate the percentage of each *_Count column so that it looks something like this:&lt;/P&gt;

&lt;P&gt;_time                                          T_Count  T%  M_Count M%  E_Count E%  G_Count G%  P_Count P%  L_Count L%  U_Count U%  X_Count X%  Total&lt;BR /&gt;
2018-05-30T00:00:00.000-0700    0   0   0   0   13  3.59    19  5.25    16  4.42    27  7.46    0   0   287 79.28   362&lt;BR /&gt;
2018-05-30T00:15:00.000-0700    0   0   0   0   8   3.11    9   3.5 9   3.5 3   1.17    0   0   228 88.72   257&lt;BR /&gt;
2018-05-30T00:30:00.000-0700    0   0   0   0   6   2.45    4   1.63    17  6.94    1   0.41    0   0   217 88.57   245&lt;BR /&gt;
2018-05-30T00:45:00.000-0700    0   0   0   0   8   3.49    7   3.06    28  12.23   0   0   0   0   186 81.22   229&lt;BR /&gt;
2018-05-30T01:00:00.000-0700    0   0   0   0   3   1.49    6   2.99    21  10.45   0   0   0   0   171 85.07   201&lt;/P&gt;

&lt;P&gt;And then finally I'd like to be able to do a line chart of just the percentages, not the count, on a 15min interval.&lt;/P&gt;

&lt;P&gt;Any feedback/suggestion will help. &lt;/P&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:47:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-percentage-of-multiple-columns-and-then-create-a-chart/m-p/432184#M123480</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2020-09-29T19:47:25Z</dc:date>
    </item>
    <item>
      <title>Re: calculate percentage of multiple columns and then create a chart</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-percentage-of-multiple-columns-and-then-create-a-chart/m-p/432185#M123481</link>
      <description>&lt;P&gt;@mmdacutanan, please pipe the following commands to your current search to get the required output. The &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Foreach"&gt;foreach&lt;/A&gt; command will perform template eval function on the required fields:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;YourCurrentSearchForCountAndTotal&amp;gt;
|  foreach "*_Count"
    [eval "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;_Perc%"=round(('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'/Total)*100,1)]
|  table _time "*_Perc%" Total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search based on the sample data provided. The commands till from &lt;CODE&gt;| makeresults&lt;/CODE&gt; till &lt;CODE&gt;| table _time * Total&lt;/CODE&gt; generate dummy data as per first table in the question:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="2018-05-30T00:00:00.000-0700 0 0 13 19 16 27 0 287 362;2018-05-30T00:15:00.000-0700 0 0 8 9 9 3 0 228 257;2018-05-30T00:30:00.000-0700 0 0 6 4 17 1 0 217 245;2018-05-30T00:45:00.000-0700 0 0 8 7 28 0 0 186 229;2018-05-30T01:00:00.000-0700 0 0 3 6 21 0 0 171 201"
|  makemv data delim=";"
|  mvexpand data
|  makemv data delim=" "
|  eval _time=strptime(mvindex(data,0),"%Y-%m-%dT%H:%M:%S.%3N%z"), T_Count=mvindex(data,1), M_Count=mvindex(data,2), E_Count=mvindex(data,3), G_Count=mvindex(data,4), P_Count=mvindex(data,5), L_Count=mvindex(data,6), U_Count=mvindex(data,7), X_Count=mvindex(data,8), Total=mvindex(data,9)
|  fields - data
|  table _time * Total
|  foreach "*_Count"
    [eval "&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;_Perc%"=round(('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'/Total)*100,1)]
|  table _time "*_Perc%" Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 05:47:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-percentage-of-multiple-columns-and-then-create-a-chart/m-p/432185#M123481</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-31T05:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: calculate percentage of multiple columns and then create a chart</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-percentage-of-multiple-columns-and-then-create-a-chart/m-p/432186#M123482</link>
      <description>&lt;P&gt;Thank you so much niketnilay! This is giving me what I need. I was playing around with foreach function before but I was not doing it right. Now i know &lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt; Really appreciate your help! &lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 20:16:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-percentage-of-multiple-columns-and-then-create-a-chart/m-p/432186#M123482</guid>
      <dc:creator>mmdacutanan</dc:creator>
      <dc:date>2018-06-01T20:16:47Z</dc:date>
    </item>
    <item>
      <title>Re: calculate percentage of multiple columns and then create a chart</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculate-percentage-of-multiple-columns-and-then-create-a-chart/m-p/432187#M123483</link>
      <description>&lt;P&gt;I am glad you got it to work! foreach takes some time to get to specially if you code foreach differently in your day to day code &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 20:27:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculate-percentage-of-multiple-columns-and-then-create-a-chart/m-p/432187#M123483</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-06-01T20:27:23Z</dc:date>
    </item>
  </channel>
</rss>

