<?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 calculate moving average based on 2 fields? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403888#M167332</link>
    <description>&lt;P&gt;[your search ] | eval purchaseprice  = (item_no * unit_price) | eval total_items = sum(item_no) | eval totalpurchaseval = sum(purchaseprice) | eval averageitemprice= totalpurchaseval/total_items&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 23:30:48 GMT</pubDate>
    <dc:creator>himpor</dc:creator>
    <dc:date>2020-09-29T23:30:48Z</dc:date>
    <item>
      <title>How to calculate moving average based on 2 fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403882#M167326</link>
      <description>&lt;P&gt;Hi Splunkers,&lt;BR /&gt;
Suppose I have 2 values in my seach:&lt;/P&gt;

&lt;P&gt;Date, &lt;STRONG&gt;# of items purchased, UnitPrice&lt;/STRONG&gt;&lt;BR /&gt;
Day1, &lt;STRONG&gt;4, 0.12&lt;/STRONG&gt;&lt;BR /&gt;
Day2, &lt;STRONG&gt;10, 0.10&lt;/STRONG&gt;&lt;BR /&gt;
Day3, &lt;STRONG&gt;25, 0.19&lt;/STRONG&gt;&lt;BR /&gt;
Day4, &lt;STRONG&gt;100, 0.15&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I want to calculate the average item price throughout time. I hope this question makes sense.&lt;/P&gt;

&lt;P&gt;Cheers,&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 02:49:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403882#M167326</guid>
      <dc:creator>ADRIANODL</dc:creator>
      <dc:date>2018-10-01T02:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate moving average based on 2 fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403883#M167327</link>
      <description>&lt;P&gt;If you want avg for item price then try below-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eventstats avg(UnitPrice) as avg|eval avg=round(avg,2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Oct 2018 04:05:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403883#M167327</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-10-01T04:05:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate moving average based on 2 fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403884#M167328</link>
      <description>&lt;P&gt;Sorry but this doesn't solve my problem since the average I want to calculate is derived from # of items purchased AND UnitPrice.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 09:05:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403884#M167328</guid>
      <dc:creator>ADRIANODL</dc:creator>
      <dc:date>2018-10-01T09:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate moving average based on 2 fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403885#M167329</link>
      <description>&lt;P&gt;@ADRIANODL, So what is the expected output?&lt;BR /&gt;
like for &lt;CODE&gt;# of items purchased&lt;/CODE&gt;=4 and &lt;CODE&gt;UnitPrice&lt;/CODE&gt;=0.12 then how avg is required to be calculated?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 09:31:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403885#M167329</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-10-01T09:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate moving average based on 2 fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403886#M167330</link>
      <description>&lt;P&gt;Hi mate,&lt;BR /&gt;
If for example, I buy 4 apples for 2 dollars each on day one, and 6 apples for 3 dollars each on day two, the average cost of my apples is calculated somehow like that:&lt;/P&gt;

&lt;P&gt;Total average is ((4 x$2) + (6 x $3))/(4+6) = 2.6 dollars average per apple.&lt;/P&gt;

&lt;P&gt;Now imagine I have X number of days, with different amounts of apples, and different value amounts).&lt;/P&gt;

&lt;P&gt;I'm having a hard time translating this equation into splunk commands.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Oct 2018 12:50:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403886#M167330</guid>
      <dc:creator>ADRIANODL</dc:creator>
      <dc:date>2018-10-01T12:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate moving average based on 2 fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403887#M167331</link>
      <description>&lt;P&gt;try this run anywhere search-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults |eval  apple=4,price=2|append[| makeresults |eval  apple=6,price=3]|eval product=apple*price|eventstats sum(apple) as sumApple, sum(product) as sumproduct|eval avg=sumproduct/sumApple|fields apple price avg
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Oct 2018 13:11:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403887#M167331</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-10-01T13:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate moving average based on 2 fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403888#M167332</link>
      <description>&lt;P&gt;[your search ] | eval purchaseprice  = (item_no * unit_price) | eval total_items = sum(item_no) | eval totalpurchaseval = sum(purchaseprice) | eval averageitemprice= totalpurchaseval/total_items&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:30:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403888#M167332</guid>
      <dc:creator>himpor</dc:creator>
      <dc:date>2020-09-29T23:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate moving average based on 2 fields?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403889#M167333</link>
      <description>&lt;P&gt;base query &lt;BR /&gt;
|  eval purchase_price = (unit_price * no_of_items) &lt;BR /&gt;
|  stats avg(purchase_price) &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:29:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-moving-average-based-on-2-fields/m-p/403889#M167333</guid>
      <dc:creator>himpor</dc:creator>
      <dc:date>2020-09-29T23:29:40Z</dc:date>
    </item>
  </channel>
</rss>

