<?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 Cumulative sum for calculate the average in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Cumulative-sum-for-calculate-the-average/m-p/775481#M274966</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, community.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having trouble solving a problem and hope someone can lend me a hand.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is an inventory table in wich I have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;line_id:&lt;/STRONG&gt; is the dimension for the graphic.&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;ini_inv:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt; &lt;/SPAN&gt;initial existence field (I only have the initial existence for the 1st day of the month).&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;ent_inv: &lt;/STRONG&gt;&lt;/SPAN&gt;inventory entries field.&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;sal_inv: &lt;/STRONG&gt;&lt;/SPAN&gt;inventory outputs field.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;date:&lt;/STRONG&gt; is the date of the inventory.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With those fields I can calculate the final existence of a day: &lt;EM&gt;(ini_inv + ent_inv - sal_inv).&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I only have the &lt;EM&gt;'ini_inv'&lt;/EM&gt; for the 1st day of the month, the final existence of each day is equivalent to the &lt;EM&gt;'ini_inv'&lt;/EM&gt; of&lt;/P&gt;&lt;P&gt;the next day and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i.e. If I select:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Year=2015&lt;/P&gt;&lt;P&gt;Month=02&lt;/P&gt;&lt;P&gt;Day=03&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My expression for calculating the final existence of the selected day is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sum({$&amp;lt;Day = {"&amp;lt;=$(=Day(Max(Date)))"}&amp;gt;} ini_inv + ent_inv - sal_inv)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far so good, the problem is to calculate the average existence for which I must sum the final existence of every day, from &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;day 1 to selected day (in this case 3) and divide it by the number of the selected day. That is the sum of the above &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;expression for each day from 1 to 3 divided by 3. Something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="_jivemacro_uid_14247413891527378 jive_text_macro jive_macro_code" jivemacro_uid="_14247413891527378"&gt;
&lt;P&gt;(&lt;/P&gt;
&lt;P&gt;Sum({$&amp;lt;Day = {1}&amp;gt;} ini_inv + ent_inv - sal_inv) +&amp;nbsp;&amp;nbsp; // Final existence of day 1 = 'ini_inv' of day 2.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;(Sum({$&amp;lt;Day = {1}&amp;gt;} ini_inv + ent_inv - sal_inv) +&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Sum({$&amp;lt;Day = {2}&amp;gt;} ent_inv - sal_inv)) +&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Final existence of day 2 = 'ini_inv' of day 3&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;((Sum({$&amp;lt;Day = {1}&amp;gt;} ini_inv + ent_inv - sal_inv) +&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Sum({$&amp;lt;Day = {2}&amp;gt;} ent_inv - sal_inv)) +&lt;/P&gt;
&lt;P&gt;Sum({$&amp;lt;Day = {3}&amp;gt;} ent_inv - sal_inv))&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Final existence of day 3.&lt;/P&gt;
&lt;P&gt;) / 3&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible to achieve this with an expression?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rubén.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Feb 2015 01:37:40 GMT</pubDate>
    <dc:creator />
    <dc:date>2015-02-24T01:37:40Z</dc:date>
    <item>
      <title>Cumulative sum for calculate the average</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-sum-for-calculate-the-average/m-p/775481#M274966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, community.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm having trouble solving a problem and hope someone can lend me a hand.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There is an inventory table in wich I have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;line_id:&lt;/STRONG&gt; is the dimension for the graphic.&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;ini_inv:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt; &lt;/SPAN&gt;initial existence field (I only have the initial existence for the 1st day of the month).&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;ent_inv: &lt;/STRONG&gt;&lt;/SPAN&gt;inventory entries field.&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;sal_inv: &lt;/STRONG&gt;&lt;/SPAN&gt;inventory outputs field.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;date:&lt;/STRONG&gt; is the date of the inventory.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With those fields I can calculate the final existence of a day: &lt;EM&gt;(ini_inv + ent_inv - sal_inv).&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I only have the &lt;EM&gt;'ini_inv'&lt;/EM&gt; for the 1st day of the month, the final existence of each day is equivalent to the &lt;EM&gt;'ini_inv'&lt;/EM&gt; of&lt;/P&gt;&lt;P&gt;the next day and so on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i.e. If I select:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Year=2015&lt;/P&gt;&lt;P&gt;Month=02&lt;/P&gt;&lt;P&gt;Day=03&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My expression for calculating the final existence of the selected day is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sum({$&amp;lt;Day = {"&amp;lt;=$(=Day(Max(Date)))"}&amp;gt;} ini_inv + ent_inv - sal_inv)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far so good, the problem is to calculate the average existence for which I must sum the final existence of every day, from &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;day 1 to selected day (in this case 3) and divide it by the number of the selected day. That is the sum of the above &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;expression for each day from 1 to 3 divided by 3. Something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="_jivemacro_uid_14247413891527378 jive_text_macro jive_macro_code" jivemacro_uid="_14247413891527378"&gt;
&lt;P&gt;(&lt;/P&gt;
&lt;P&gt;Sum({$&amp;lt;Day = {1}&amp;gt;} ini_inv + ent_inv - sal_inv) +&amp;nbsp;&amp;nbsp; // Final existence of day 1 = 'ini_inv' of day 2.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;(Sum({$&amp;lt;Day = {1}&amp;gt;} ini_inv + ent_inv - sal_inv) +&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Sum({$&amp;lt;Day = {2}&amp;gt;} ent_inv - sal_inv)) +&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Final existence of day 2 = 'ini_inv' of day 3&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;((Sum({$&amp;lt;Day = {1}&amp;gt;} ini_inv + ent_inv - sal_inv) +&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Sum({$&amp;lt;Day = {2}&amp;gt;} ent_inv - sal_inv)) +&lt;/P&gt;
&lt;P&gt;Sum({$&amp;lt;Day = {3}&amp;gt;} ent_inv - sal_inv))&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Final existence of day 3.&lt;/P&gt;
&lt;P&gt;) / 3&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible to achieve this with an expression?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rubén.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Feb 2015 01:37:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-sum-for-calculate-the-average/m-p/775481#M274966</guid>
      <dc:creator />
      <dc:date>2015-02-24T01:37:40Z</dc:date>
    </item>
  </channel>
</rss>

