<?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 to get the average base on line number? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-average-base-on-line-number/m-p/432413#M123558</link>
    <description>&lt;P&gt;This is so smart Thank you so much&lt;/P&gt;</description>
    <pubDate>Fri, 01 Jun 2018 00:26:13 GMT</pubDate>
    <dc:creator>samlinsongguo</dc:creator>
    <dc:date>2018-06-01T00:26:13Z</dc:date>
    <item>
      <title>How to get the average base on line number?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-average-base-on-line-number/m-p/432411#M123556</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
I have a table as below, each time run the query it may return different result&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;run 1
day1 10
day2 20
day3 25

run second time
day1 10
day2 20
day3 30
day4 10

I want to calculate the average base on how many line there are. So for each table will be calculate as below
day1 10
day2 20
day3 25
avgT 18.333
calculation: (10+20+25)/3=18.333

day1 10
day2 20
day3 30
day4 10
avgT 17.5
Calculation: (10+20+30+10)/4=17.5
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Any suggestion how I can achieve that?&lt;BR /&gt;
Thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 05:27:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-average-base-on-line-number/m-p/432411#M123556</guid>
      <dc:creator>samlinsongguo</dc:creator>
      <dc:date>2018-05-31T05:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the average base on line number?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-average-base-on-line-number/m-p/432412#M123557</link>
      <description>&lt;P&gt;@samlinsongguo please try the following run anywhere search example. Commands from &lt;CODE&gt;| makeresults&lt;/CODE&gt; till &lt;CODE&gt;| table Days Count&lt;/CODE&gt; generates the table as per the question:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|  makeresults
|  eval data="day1 10;day2 20;day3 30;day4 10"
|  makemv data delim=";"
|  mvexpand data
|  makemv data delim=" "
|  eval Days=mvindex(data,0),Count=mvindex(data,1)
|  fields - _time data
|  table Days Count
|  streamstats count as sno
|  addcoltotals Count labelfield=Days label=AvgT
|  filldown sno
|  eval Count=if(Days=="AvgT",round(Count/sno,2),Count)
|  fields - sno
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If the fields in the table above are &lt;CODE&gt;Days&lt;/CODE&gt; and &lt;CODE&gt;Count&lt;/CODE&gt;, you need to add the following code in your existing search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;yourCurrentSearch&amp;gt;
    |  streamstats count as sno
    |  addcoltotals Count labelfield=Days label=AvgT
    |  filldown sno
    |  eval Count=if(Days=="AvgT",round(Count/sno,2),Count)
    |  fields - sno
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 May 2018 14:00:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-average-base-on-line-number/m-p/432412#M123557</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-31T14:00:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to get the average base on line number?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-average-base-on-line-number/m-p/432413#M123558</link>
      <description>&lt;P&gt;This is so smart Thank you so much&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 00:26:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-the-average-base-on-line-number/m-p/432413#M123558</guid>
      <dc:creator>samlinsongguo</dc:creator>
      <dc:date>2018-06-01T00:26:13Z</dc:date>
    </item>
  </channel>
</rss>

