<?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 RangeSum in loading script in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/RangeSum-in-loading-script/m-p/2090594#M89388</link>
    <description>&lt;DIV&gt;Hello!&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I have an issue when trying to calculate the cumulative value over a period of time and can't find an answer in the community.&lt;/DIV&gt;
&lt;DIV&gt;I want to sum up the value for each month and need it to group by MonthStartDate, company name, account code and costing code.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;For example, if MonthStartDate = 2016-12-01, Company A, Account = 1, Costing Code = X have amount 100.&lt;/DIV&gt;
&lt;DIV&gt;For the next month, 2017-01-01 the amount is 150 for the same company, etc., I would like to have the value 250.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;As of now it returns 100 and then 150.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;When using&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; (Sum(Aggr( Rangesum(Above(Sum(SUM_AmountEUR),0,RowNo())), (ReferenceDate1, (Numeric, Ascending)))))&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;in a table it works perfectly, but I need it in the script.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;What I do is I create zeroes for the months not containing any data, as I need it for every month, and then I sum the amount.&amp;nbsp;Thereafter, I use the RangeSum-function and order by MonthStartDate, company name, account code and costing code&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;In the rangesum-function I have also tried do add the sum-function and group by once more but it does not work.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;What am I missing?&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Here is the code I'm trying to get to work&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;LET vStartDate = Num('2016-12-01');&lt;/DIV&gt;
&lt;DIV&gt;LET vEndDate = Num(today());&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;temp_OpeningBalance:&lt;/DIV&gt;
&lt;DIV&gt;LOAD&lt;/DIV&gt;
&lt;DIV&gt;MonthStart($(vStartDate), IterNo()-1) as Date,&lt;/DIV&gt;
&lt;DIV&gt;'0' AS Amount&lt;/DIV&gt;
&lt;DIV&gt;AutoGenerate 1&lt;/DIV&gt;
&lt;DIV&gt;While MonthStart($(vStartDate), IterNo()-1) &amp;lt;= $(vEndDate);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Join (temp_OpeningBalance)&lt;/DIV&gt;
&lt;DIV&gt;Load Distinct&lt;/DIV&gt;
&lt;DIV&gt;CompanyName,&lt;/DIV&gt;
&lt;DIV&gt;Account,&lt;/DIV&gt;
&lt;DIV&gt;CostingCode&lt;/DIV&gt;
&lt;DIV&gt;Resident Fact;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;temp_OpeningBalance:&lt;/DIV&gt;
&lt;DIV&gt;Concatenate(temp_OpeningBalance)&lt;/DIV&gt;
&lt;DIV&gt;Load&lt;/DIV&gt;
&lt;DIV&gt;MonthStart(Date) AS MonthStartDate,&lt;/DIV&gt;
&lt;DIV&gt;CompanyName,&lt;/DIV&gt;
&lt;DIV&gt;Account,&lt;/DIV&gt;
&lt;DIV&gt;CostingCode2,&lt;/DIV&gt;
&lt;DIV&gt;SUM(Amount) AS SUM_Amount&lt;/DIV&gt;
&lt;DIV&gt;Resident Fact&lt;/DIV&gt;
&lt;DIV&gt;Group By MonthStartDate, CompanyName, Account, CostingCode;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;OpeningBalance:&lt;/DIV&gt;
&lt;DIV&gt;Load&lt;/DIV&gt;
&lt;DIV&gt;MonthStartDate,&lt;/DIV&gt;
&lt;DIV&gt;CompanyName,&lt;/DIV&gt;
&lt;DIV&gt;Account,&lt;/DIV&gt;
&lt;DIV&gt;CostingCode,&lt;/DIV&gt;
&lt;DIV&gt;SUM_Amount,&lt;/DIV&gt;
&lt;DIV&gt;if(Account = previous(Account) and CompanyName = previous(CompanyName) and CostingCode = previous(CostingCode) and Date = previous(Date),&lt;/DIV&gt;
&lt;DIV&gt;RangeSum(SUM_Amount, peek('OB_Amount')), SUM_Amount) as OB_Amount&lt;/DIV&gt;
&lt;DIV&gt;Resident temp_OpeningBalance&lt;/DIV&gt;
&lt;DIV&gt;ORDER BY MonthStartDate, CompanyName,&amp;nbsp;Account, CostingCode;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Wed, 05 Jul 2023 08:42:35 GMT</pubDate>
    <dc:creator>AJZ</dc:creator>
    <dc:date>2023-07-05T08:42:35Z</dc:date>
    <item>
      <title>RangeSum in loading script</title>
      <link>https://community.qlik.com/t5/App-Development/RangeSum-in-loading-script/m-p/2090594#M89388</link>
      <description>&lt;DIV&gt;Hello!&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;I have an issue when trying to calculate the cumulative value over a period of time and can't find an answer in the community.&lt;/DIV&gt;
&lt;DIV&gt;I want to sum up the value for each month and need it to group by MonthStartDate, company name, account code and costing code.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;For example, if MonthStartDate = 2016-12-01, Company A, Account = 1, Costing Code = X have amount 100.&lt;/DIV&gt;
&lt;DIV&gt;For the next month, 2017-01-01 the amount is 150 for the same company, etc., I would like to have the value 250.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;As of now it returns 100 and then 150.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;When using&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; (Sum(Aggr( Rangesum(Above(Sum(SUM_AmountEUR),0,RowNo())), (ReferenceDate1, (Numeric, Ascending)))))&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;in a table it works perfectly, but I need it in the script.&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;What I do is I create zeroes for the months not containing any data, as I need it for every month, and then I sum the amount.&amp;nbsp;Thereafter, I use the RangeSum-function and order by MonthStartDate, company name, account code and costing code&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;In the rangesum-function I have also tried do add the sum-function and group by once more but it does not work.&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;What am I missing?&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Here is the code I'm trying to get to work&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;LET vStartDate = Num('2016-12-01');&lt;/DIV&gt;
&lt;DIV&gt;LET vEndDate = Num(today());&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;temp_OpeningBalance:&lt;/DIV&gt;
&lt;DIV&gt;LOAD&lt;/DIV&gt;
&lt;DIV&gt;MonthStart($(vStartDate), IterNo()-1) as Date,&lt;/DIV&gt;
&lt;DIV&gt;'0' AS Amount&lt;/DIV&gt;
&lt;DIV&gt;AutoGenerate 1&lt;/DIV&gt;
&lt;DIV&gt;While MonthStart($(vStartDate), IterNo()-1) &amp;lt;= $(vEndDate);&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Join (temp_OpeningBalance)&lt;/DIV&gt;
&lt;DIV&gt;Load Distinct&lt;/DIV&gt;
&lt;DIV&gt;CompanyName,&lt;/DIV&gt;
&lt;DIV&gt;Account,&lt;/DIV&gt;
&lt;DIV&gt;CostingCode&lt;/DIV&gt;
&lt;DIV&gt;Resident Fact;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;temp_OpeningBalance:&lt;/DIV&gt;
&lt;DIV&gt;Concatenate(temp_OpeningBalance)&lt;/DIV&gt;
&lt;DIV&gt;Load&lt;/DIV&gt;
&lt;DIV&gt;MonthStart(Date) AS MonthStartDate,&lt;/DIV&gt;
&lt;DIV&gt;CompanyName,&lt;/DIV&gt;
&lt;DIV&gt;Account,&lt;/DIV&gt;
&lt;DIV&gt;CostingCode2,&lt;/DIV&gt;
&lt;DIV&gt;SUM(Amount) AS SUM_Amount&lt;/DIV&gt;
&lt;DIV&gt;Resident Fact&lt;/DIV&gt;
&lt;DIV&gt;Group By MonthStartDate, CompanyName, Account, CostingCode;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;OpeningBalance:&lt;/DIV&gt;
&lt;DIV&gt;Load&lt;/DIV&gt;
&lt;DIV&gt;MonthStartDate,&lt;/DIV&gt;
&lt;DIV&gt;CompanyName,&lt;/DIV&gt;
&lt;DIV&gt;Account,&lt;/DIV&gt;
&lt;DIV&gt;CostingCode,&lt;/DIV&gt;
&lt;DIV&gt;SUM_Amount,&lt;/DIV&gt;
&lt;DIV&gt;if(Account = previous(Account) and CompanyName = previous(CompanyName) and CostingCode = previous(CostingCode) and Date = previous(Date),&lt;/DIV&gt;
&lt;DIV&gt;RangeSum(SUM_Amount, peek('OB_Amount')), SUM_Amount) as OB_Amount&lt;/DIV&gt;
&lt;DIV&gt;Resident temp_OpeningBalance&lt;/DIV&gt;
&lt;DIV&gt;ORDER BY MonthStartDate, CompanyName,&amp;nbsp;Account, CostingCode;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Jul 2023 08:42:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/RangeSum-in-loading-script/m-p/2090594#M89388</guid>
      <dc:creator>AJZ</dc:creator>
      <dc:date>2023-07-05T08:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: RangeSum in loading script</title>
      <link>https://community.qlik.com/t5/App-Development/RangeSum-in-loading-script/m-p/2090630#M89392</link>
      <description>&lt;P&gt;use previous function instead of&amp;nbsp; Peek.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;if(Account = previous(Account) and CompanyName = previous(CompanyName) and CostingCode = previous(CostingCode) and Date = previous(Date),&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;(SUM_Amount+Previous(SUM_Amount) )&lt;/SPAN&gt;, SUM_Amount) as OB_Amount&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Jul 2023 09:47:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/RangeSum-in-loading-script/m-p/2090630#M89392</guid>
      <dc:creator>udit_k</dc:creator>
      <dc:date>2023-07-05T09:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: RangeSum in loading script</title>
      <link>https://community.qlik.com/t5/App-Development/RangeSum-in-loading-script/m-p/2090678#M89398</link>
      <description>&lt;P&gt;Thanks for the quick reply.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;However, this does not work. It just returns the same value as in the field&amp;nbsp;&lt;SPAN&gt;SUM_Amount when selecting AccountCode and missing a lot of data when selecting other fields as well.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I need to sum up all preceeding months and this would just return the current + last value&lt;/SPAN&gt;&lt;SPAN&gt;?&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 11:24:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/RangeSum-in-loading-script/m-p/2090678#M89398</guid>
      <dc:creator>AJZ</dc:creator>
      <dc:date>2023-07-05T11:24:09Z</dc:date>
    </item>
  </channel>
</rss>

