<?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 do you add all the values in a column to get the total and then divide the total by the number of rows in the column? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472829#M133082</link>
    <description>&lt;P&gt;If you want to add additional columns with statistics, use eventstats:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eventstats count sum(foo) avg(foo)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you just want the statistics, use stats:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count sum(foo) avg(foo)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm not sure what particular statistic you're asking for, so those two are just examples similar to the words you used.&lt;/P&gt;</description>
    <pubDate>Sat, 15 Feb 2020 23:34:16 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2020-02-15T23:34:16Z</dc:date>
    <item>
      <title>How do you add all the values in a column to get the total and then divide the total by the number of rows in the column?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472828#M133081</link>
      <description>&lt;P&gt;The column to the right has a total of the percentage increase, but I would like to take that total and divide it by the number of rows that made the total.&lt;/P&gt;

&lt;P&gt;source="im_positions*.csv" sourcetype="stock-Positions:csv" &lt;BR /&gt;
    | dedup Symbol&lt;BR /&gt;
    | rename "Market Value" as mv&lt;BR /&gt;
    | rename "Estimated Gain_Loss" as egl&lt;BR /&gt;
     | rex field=mv mode=sed "s/,//"&lt;BR /&gt;
     | rex field=egl mode=sed "s/,//"&lt;BR /&gt;
     | rex field=Price mode=sed "s/,//"&lt;BR /&gt;
    | replace $* with * in Price&lt;BR /&gt;
    | replace $* with * in egl&lt;BR /&gt;
    | replace N/A with 0 in egl&lt;BR /&gt;
    | replace $* with * in mv&lt;BR /&gt;
    | replace &lt;EM&gt;.000 with * in Quantity&lt;BR /&gt;
    | eval originalprice = (mv - egl)/Quantity&lt;BR /&gt;
    | eval eglneg=egl&lt;BR /&gt;
    | replace -&lt;/EM&gt; with * in eglneg&lt;BR /&gt;
    | replace $* with * in eglneg&lt;BR /&gt;
    | replace N/A with 0 in eglneg&lt;BR /&gt;
    | eval originalpriceneg = (mv)+(eglneg)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval originalprice=if(isnull(originalprice), originalpriceneg, originalprice)

| eval Percent = round(((Price - originalprice)/originalprice*100),0)

| table Symbol Description Quantity originalprice Price egl  mv  Percent
| rename originalprice as "Purchased Price"
| rename Price as "Current Price"
| rename mv as "Market Value"
| rename Percent as "Percentage Increase"
| rename  egl as "Estimated Gain_Loss"
| rename Quantity as "# of Shares"
| addcoltotals 
| sort -"Estimated Gain_Loss"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="https://community.splunk.com/storage/temp/283642-stocks.jpg" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 04:12:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472828#M133081</guid>
      <dc:creator>ihaveasplunkacc</dc:creator>
      <dc:date>2020-09-30T04:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do you add all the values in a column to get the total and then divide the total by the number of rows in the column?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472829#M133082</link>
      <description>&lt;P&gt;If you want to add additional columns with statistics, use eventstats:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eventstats count sum(foo) avg(foo)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you just want the statistics, use stats:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats count sum(foo) avg(foo)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'm not sure what particular statistic you're asking for, so those two are just examples similar to the words you used.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Feb 2020 23:34:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472829#M133082</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2020-02-15T23:34:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do you add all the values in a column to get the total and then divide the total by the number of rows in the column?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472830#M133083</link>
      <description>&lt;P&gt;Thank you, but that is not exactly what I am looking for.&lt;/P&gt;

&lt;P&gt;Field=percentage with a value=.25&lt;BR /&gt;
and the second value in the field&lt;BR /&gt;
Field=percentage with a value=.50&lt;/P&gt;

&lt;P&gt;If I add them I get a total of .75, but I want to divide that total by the number of values added to make it.  In this case it would be .75/2=.375&lt;/P&gt;

&lt;P&gt;So if I I have a column of percentages, I want to add them all up and then divide the total by the number of values that made the sum.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Feb 2020 23:45:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472830#M133083</guid>
      <dc:creator>ihaveasplunkacc</dc:creator>
      <dc:date>2020-02-15T23:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do you add all the values in a column to get the total and then divide the total by the number of rows in the column?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472831#M133084</link>
      <description>&lt;P&gt;So... an average?&lt;/P&gt;</description>
      <pubDate>Sat, 15 Feb 2020 23:59:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472831#M133084</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2020-02-15T23:59:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do you add all the values in a column to get the total and then divide the total by the number of rows in the column?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472832#M133085</link>
      <description>&lt;P&gt;My bad.  You were absolutely correct. &lt;BR /&gt;
Thank you&lt;/P&gt;</description>
      <pubDate>Sun, 16 Feb 2020 00:12:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-you-add-all-the-values-in-a-column-to-get-the-total-and/m-p/472832#M133085</guid>
      <dc:creator>ihaveasplunkacc</dc:creator>
      <dc:date>2020-02-16T00:12:44Z</dc:date>
    </item>
  </channel>
</rss>

