<?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 average of specific fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635239#M220699</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/15147"&gt;@somesoni2&lt;/a&gt;&amp;nbsp; This isn't giving me any output,I don't see any additional field being added to the result.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Also, I want to show the average for Q1_score PREPAID &amp;amp; so on in&amp;nbsp; "count by segment" row i.e. at the bottom row&lt;/P&gt;&lt;PRE&gt;| eventstats avg("Q1_score PREPAID") as "Avg Q1_score PREPAID" ,avg("Q2_score PREPAID") as "Avg Q2_score PREPAID",avg("Q1_score CONSUMER") as "Avg Q1_score CONSUMER"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Mar 2023 06:21:34 GMT</pubDate>
    <dc:creator>Ashwini008</dc:creator>
    <dc:date>2023-03-21T06:21:34Z</dc:date>
    <item>
      <title>How to calculate average of specific fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635176#M220686</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I am formatting data as required and getting it in below format. Now I want to calculate average of only highlighted fields in green color i.e. Q1_score PREPAID,Q2_score PREPAID,Q1_score CONSUMER so on&lt;/P&gt;
&lt;P&gt;Example&amp;nbsp;Q1_score CONSUMER ,Count by segment value should be 4.50&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ashwini008_0-1679334983161.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24385i43F7758E8CD33AB0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ashwini008_0-1679334983161.png" alt="Ashwini008_0-1679334983161.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;This is last piece of my query&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;| addcoltotals COUNT* Q1* Q2* Q3* Total 
| eval Month=coalesce(Month, "Count by Segment") &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;Please suggest&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 16:20:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635176#M220686</guid>
      <dc:creator>Ashwini008</dc:creator>
      <dc:date>2023-03-21T16:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average of specific fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635179#M220687</link>
      <description>&lt;P&gt;To be fully honest, I don't understand what you want to do. Especially that I don't see any average that should come down to 4.50&lt;/P&gt;&lt;P&gt;But as a general rule, sometimes it's better to do some additional calculations earlier and then aggregate the results in the end instead of - for example - adding totals and then trying to do additional stuff since totals can get in the way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 18:23:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635179#M220687</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2023-03-20T18:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average of specific fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635186#M220688</link>
      <description>&lt;P&gt;If the field names are static, you can use eventstats to calculate average of those specific fields like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Your current search generating those columns
| eventstats avg("Q1_score PREPAID") as "Avg Q1_score PREPAID" ,avg("Q2_score PREPAID") as "Avg Q2_score PREPAID",avg("Q1_score CONSUMER") as "Avg Q1_score CONSUMER"&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 20 Mar 2023 18:57:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635186#M220688</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2023-03-20T18:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average of specific fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635239#M220699</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/15147"&gt;@somesoni2&lt;/a&gt;&amp;nbsp; This isn't giving me any output,I don't see any additional field being added to the result.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Also, I want to show the average for Q1_score PREPAID &amp;amp; so on in&amp;nbsp; "count by segment" row i.e. at the bottom row&lt;/P&gt;&lt;PRE&gt;| eventstats avg("Q1_score PREPAID") as "Avg Q1_score PREPAID" ,avg("Q2_score PREPAID") as "Avg Q2_score PREPAID",avg("Q1_score CONSUMER") as "Avg Q1_score CONSUMER"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 06:21:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635239#M220699</guid>
      <dc:creator>Ashwini008</dc:creator>
      <dc:date>2023-03-21T06:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate average of specific fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635245#M220703</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/15147"&gt;@somesoni2&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/231884"&gt;@PickleRick&lt;/a&gt;&amp;nbsp; Below code was my fix&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval var=1 
| addcoltotals COUNT* Q1* Q2* Q3* var Total 
| foreach Q1_Score* 
    [ eval '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' = round('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'/var,2)] 
| foreach Q2_Score* 
    [ eval '&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' = round('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'/var,2)] &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 07:37:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-average-of-specific-fields/m-p/635245#M220703</guid>
      <dc:creator>Ashwini008</dc:creator>
      <dc:date>2023-03-21T07:37:53Z</dc:date>
    </item>
  </channel>
</rss>

