<?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: Finding the Moving Average of a Data Series in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Finding-the-Moving-Average-of-a-Data-Series/m-p/2072884#M1223699</link>
    <description>&lt;P&gt;I did once a moving average in the script. Not sure if it is the right or more efficient way but the concept was to create a cumulative add of the previous value, so you need to be careful ordering your dataset ASC by Date. Let's say you have Date, Dim1, Metric1:&lt;/P&gt;
&lt;P&gt;ATemp:&lt;/P&gt;
&lt;P&gt;Load DATE,&lt;/P&gt;
&lt;P&gt;Dim1,&lt;/P&gt;
&lt;P&gt;Metric1&lt;/P&gt;
&lt;P&gt;FROM Table;&lt;/P&gt;
&lt;P&gt;You need to iterate by a Dim1 value list:&lt;/P&gt;
&lt;P&gt;for Each vDim1 in $(vDim1List)&lt;/P&gt;
&lt;P&gt;A:&lt;BR /&gt;LOAD *,&lt;BR /&gt;rangesum(Metric1,peek('Dim1_1')) as Dim1_1&lt;BR /&gt;Resident ATemp&lt;BR /&gt;order by DATE Asc;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, you create a new column by looking for the X moving avg value you need&lt;/P&gt;
&lt;P&gt;B:&lt;BR /&gt;Load *,&lt;BR /&gt;RowNo()-7 as Rowno7&lt;BR /&gt;resident A;&lt;/P&gt;
&lt;P&gt;DROP Table A;&lt;/P&gt;
&lt;P&gt;Next vDim1&lt;/P&gt;
&lt;P&gt;Finally, you calculate the moving avg, having in mind that the first X rows will not have an average:&lt;/P&gt;
&lt;P&gt;Rolling:&lt;BR /&gt;LOAD *,&lt;BR /&gt;if(num(DATE)=num('1/8/2023'),Dim1_1/7,if(num(DATE)&amp;gt;num('1/8/2020'),(Dim1_1-peek('Dim1_1',Rowno7-1))/7,Dim1)) as RollingAvg&lt;BR /&gt;from table (qvd);&lt;/P&gt;
&lt;P&gt;You will need to adapt this code for sure but hopefully it helps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 May 2023 13:34:35 GMT</pubDate>
    <dc:creator>chematos</dc:creator>
    <dc:date>2023-05-18T13:34:35Z</dc:date>
    <item>
      <title>Finding the Moving Average of a Data Series</title>
      <link>https://community.qlik.com/t5/QlikView/Finding-the-Moving-Average-of-a-Data-Series/m-p/2070908#M1223612</link>
      <description>&lt;DIV class="mb-sm mb-xs px-md xs:px-0"&gt;
&lt;DIV id="t3_iyyve4-post-rtjson-content" class="text-neutral-content md max-h-[253px] overflow-hidden s:max-h-[318px] m:max-h-[337px] l:max-h-[352px] xl:max-h-[452px] text-14 "&gt;
&lt;P&gt;Hi Again!&lt;/P&gt;
&lt;P&gt;I am looking to calculate the moving average of a data series (e.g. MA 7 days). Is it possible to do this by going to the Data Manager tab &amp;gt; Calculated Field &amp;gt; Creating an Expression for the moving average?&lt;/P&gt;
&lt;P&gt;Or do I need to write a script? I assume that's under Data Manager &amp;gt; Data Load Editor.&lt;/P&gt;
&lt;P&gt;Thanks in advance for any advice!&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Sat, 13 May 2023 01:49:13 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Finding-the-Moving-Average-of-a-Data-Series/m-p/2070908#M1223612</guid>
      <dc:creator>khenapart</dc:creator>
      <dc:date>2023-05-13T01:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Finding the Moving Average of a Data Series</title>
      <link>https://community.qlik.com/t5/QlikView/Finding-the-Moving-Average-of-a-Data-Series/m-p/2072884#M1223699</link>
      <description>&lt;P&gt;I did once a moving average in the script. Not sure if it is the right or more efficient way but the concept was to create a cumulative add of the previous value, so you need to be careful ordering your dataset ASC by Date. Let's say you have Date, Dim1, Metric1:&lt;/P&gt;
&lt;P&gt;ATemp:&lt;/P&gt;
&lt;P&gt;Load DATE,&lt;/P&gt;
&lt;P&gt;Dim1,&lt;/P&gt;
&lt;P&gt;Metric1&lt;/P&gt;
&lt;P&gt;FROM Table;&lt;/P&gt;
&lt;P&gt;You need to iterate by a Dim1 value list:&lt;/P&gt;
&lt;P&gt;for Each vDim1 in $(vDim1List)&lt;/P&gt;
&lt;P&gt;A:&lt;BR /&gt;LOAD *,&lt;BR /&gt;rangesum(Metric1,peek('Dim1_1')) as Dim1_1&lt;BR /&gt;Resident ATemp&lt;BR /&gt;order by DATE Asc;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, you create a new column by looking for the X moving avg value you need&lt;/P&gt;
&lt;P&gt;B:&lt;BR /&gt;Load *,&lt;BR /&gt;RowNo()-7 as Rowno7&lt;BR /&gt;resident A;&lt;/P&gt;
&lt;P&gt;DROP Table A;&lt;/P&gt;
&lt;P&gt;Next vDim1&lt;/P&gt;
&lt;P&gt;Finally, you calculate the moving avg, having in mind that the first X rows will not have an average:&lt;/P&gt;
&lt;P&gt;Rolling:&lt;BR /&gt;LOAD *,&lt;BR /&gt;if(num(DATE)=num('1/8/2023'),Dim1_1/7,if(num(DATE)&amp;gt;num('1/8/2020'),(Dim1_1-peek('Dim1_1',Rowno7-1))/7,Dim1)) as RollingAvg&lt;BR /&gt;from table (qvd);&lt;/P&gt;
&lt;P&gt;You will need to adapt this code for sure but hopefully it helps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2023 13:34:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Finding-the-Moving-Average-of-a-Data-Series/m-p/2072884#M1223699</guid>
      <dc:creator>chematos</dc:creator>
      <dc:date>2023-05-18T13:34:35Z</dc:date>
    </item>
  </channel>
</rss>

