<?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: Cumulative Sum in load scipt in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-scipt/m-p/2097945#M89914</link>
    <description>&lt;P&gt;Hi ZimaBlue.&lt;/P&gt;
&lt;P&gt;Here's an example script that might help you. This example assumes you have a table called 'Orders' that contains a 'User_Id', 'Order_Date', and 'Order_Amount' fields:&lt;/P&gt;
&lt;P&gt;RawData:&lt;BR /&gt;LOAD&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date,&lt;BR /&gt;Order_Amount&lt;BR /&gt;FROM&lt;BR /&gt;Orders&lt;BR /&gt;ORDER BY&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date ASC;&lt;/P&gt;
&lt;P&gt;TempTable:&lt;BR /&gt;LOAD&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date,&lt;BR /&gt;Order_Amount,&lt;BR /&gt;IterNo() as RowNum&lt;BR /&gt;RESIDENT&lt;BR /&gt;RawData&lt;BR /&gt;WHILE IterNo() &amp;lt;= Peek('RowNum', -1, 'RawData') + 30 AND Peek('User_Id', -IterNo()) = User_Id;&lt;/P&gt;
&lt;P&gt;FinalTable:&lt;BR /&gt;LOAD&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date,&lt;BR /&gt;Sum(Order_Amount) as RollingOrderSum&lt;BR /&gt;RESIDENT&lt;BR /&gt;TempTable&lt;BR /&gt;GROUP BY&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date;&lt;/P&gt;
&lt;P&gt;DROP TABLES&lt;BR /&gt;RawData,&lt;BR /&gt;TempTable;&lt;/P&gt;
&lt;P&gt;The script first loads the original data into a temporary table 'RawData' in the order of 'User_Id' and 'Order_Date'. Then, it creates a second temporary table 'TempTable' that replicates each row from 'RawData' into as many rows as there are within the previous 30 rows (or fewer if there are less than 30) with the same 'User_Id'. Finally, it creates 'FinalTable' by aggregating 'TempTable' to get the sum of 'Order_Amount' for each 'User_Id' and 'Order_Date'. The 'RawData' and 'TempTable' are then dropped as they're no longer needed.&lt;/P&gt;
&lt;P&gt;Please note that this script assumes that you have a single record for each user and date. If you have multiple records for the same user and date, you should pre-aggregate them before using this script. Also, be aware that if your data is large, this script may take a long time to execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2023 15:39:23 GMT</pubDate>
    <dc:creator>cristianj23a</dc:creator>
    <dc:date>2023-07-27T15:39:23Z</dc:date>
    <item>
      <title>Cumulative Sum in load scipt</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-scipt/m-p/2097878#M89910</link>
      <description>&lt;P&gt;Hello!,&lt;/P&gt;
&lt;P&gt;I'm trying to find a way to calculate the cumulative total in the load script. I found an article with a formula like &lt;FONT face="courier new,courier" color="#0000FF"&gt;Range Sum(Above(sum(Sales),0,Rovno()))&lt;/FONT&gt;, but as far as I understand, this does not work in the load script, because qlik sees &lt;FONT face="courier new,courier" color="#0000FF"&gt;Above&lt;/FONT&gt; as a field name, not as a function.&lt;/P&gt;
&lt;P&gt;What I need: count for each &lt;FONT face="courier new,courier" color="#FF6600"&gt;customer|date&lt;/FONT&gt; row the sum of all customer orders for the last 30 days. The database is sorted as &lt;FONT face="courier new,courier" color="#0000FF"&gt;order by user_id, order_date asc&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;I need to check that in all the previous 29 rows the &lt;FONT face="courier new,courier" color="#FF6600"&gt;user_id&lt;/FONT&gt; is the same and calculate the cumulative total in each row (data is needed for every day). So something like:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;user1| order_date1 | sum of all orders for last 30 days&amp;nbsp;from this date&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;user1| order_date2| sum of all orders for last 30 days&amp;nbsp;from this date&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Also, if there is less than 30, I want to see the cumulative total for the period that we have, within 30 days. Unfortunately, our sql version is very old, so I can't calculate this sum in the sql script. I need to calculate this in qlik sense.&lt;/P&gt;
&lt;P&gt;Thank you for any help!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 13:00:17 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-scipt/m-p/2097878#M89910</guid>
      <dc:creator>ZimaBlue</dc:creator>
      <dc:date>2023-07-27T13:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load scipt</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-scipt/m-p/2097945#M89914</link>
      <description>&lt;P&gt;Hi ZimaBlue.&lt;/P&gt;
&lt;P&gt;Here's an example script that might help you. This example assumes you have a table called 'Orders' that contains a 'User_Id', 'Order_Date', and 'Order_Amount' fields:&lt;/P&gt;
&lt;P&gt;RawData:&lt;BR /&gt;LOAD&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date,&lt;BR /&gt;Order_Amount&lt;BR /&gt;FROM&lt;BR /&gt;Orders&lt;BR /&gt;ORDER BY&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date ASC;&lt;/P&gt;
&lt;P&gt;TempTable:&lt;BR /&gt;LOAD&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date,&lt;BR /&gt;Order_Amount,&lt;BR /&gt;IterNo() as RowNum&lt;BR /&gt;RESIDENT&lt;BR /&gt;RawData&lt;BR /&gt;WHILE IterNo() &amp;lt;= Peek('RowNum', -1, 'RawData') + 30 AND Peek('User_Id', -IterNo()) = User_Id;&lt;/P&gt;
&lt;P&gt;FinalTable:&lt;BR /&gt;LOAD&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date,&lt;BR /&gt;Sum(Order_Amount) as RollingOrderSum&lt;BR /&gt;RESIDENT&lt;BR /&gt;TempTable&lt;BR /&gt;GROUP BY&lt;BR /&gt;User_Id,&lt;BR /&gt;Order_Date;&lt;/P&gt;
&lt;P&gt;DROP TABLES&lt;BR /&gt;RawData,&lt;BR /&gt;TempTable;&lt;/P&gt;
&lt;P&gt;The script first loads the original data into a temporary table 'RawData' in the order of 'User_Id' and 'Order_Date'. Then, it creates a second temporary table 'TempTable' that replicates each row from 'RawData' into as many rows as there are within the previous 30 rows (or fewer if there are less than 30) with the same 'User_Id'. Finally, it creates 'FinalTable' by aggregating 'TempTable' to get the sum of 'Order_Amount' for each 'User_Id' and 'Order_Date'. The 'RawData' and 'TempTable' are then dropped as they're no longer needed.&lt;/P&gt;
&lt;P&gt;Please note that this script assumes that you have a single record for each user and date. If you have multiple records for the same user and date, you should pre-aggregate them before using this script. Also, be aware that if your data is large, this script may take a long time to execute.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 15:39:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-scipt/m-p/2097945#M89914</guid>
      <dc:creator>cristianj23a</dc:creator>
      <dc:date>2023-07-27T15:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load scipt</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-scipt/m-p/2102017#M90045</link>
      <description>&lt;P&gt;Thank you for such a detailed answer! Sorry for the long answer. I get an empty table at this stage.&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;TempTable:&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;LOAD&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;User_Id,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;Order_Date,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;Order_Amount,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;IterNo() as RowNum&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;RESIDENT&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;RawData&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier" color="#0000FF"&gt;WHILE IterNo() &amp;lt;= Peek('RowNum', -1, 'RawData') + 30 AND Peek('User_Id', -IterNo()) = User_Id;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I also tried to remove the quotes for the field names, but it didn't help. Can I do something wrong?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 10:07:04 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-scipt/m-p/2102017#M90045</guid>
      <dc:creator>ZimaBlue</dc:creator>
      <dc:date>2023-08-03T10:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load scipt</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-scipt/m-p/2102174#M90063</link>
      <description>&lt;P&gt;Hello I don't see the quotes in your data or I don't understand your question well, but one way to remove values that you don't want is using REPLACE or SUBFIELD.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.qlik.com/en-US/qlikview/May2023/Subsystems/Client/Content/QV_QlikView/Scripting/StringFunctions/Replace.htm#:~:text=Replace()%20returns%20a%20string,works%20from%20left%20to%20right" target="_blank"&gt;https://help.qlik.com/en-US/qlikview/May2023/Subsystems/Client/Content/QV_QlikView/Scripting/StringFunctions/Replace.htm#:~:text=Replace()%20returns%20a%20string,works%20from%20left%20to%20right&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.qlik.com/en-US/sense/May2023/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/SubField.htm" target="_blank"&gt;https://help.qlik.com/en-US/sense/May2023/Subsystems/Hub/Content/Sense_Hub/Scripting/StringFunctions/SubField.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regarts.&lt;/P&gt;
&lt;DIV id="gtx-trans" style="position: absolute; left: -19px; top: 36.9826px;"&gt;
&lt;DIV class="gtx-trans-icon"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 03 Aug 2023 15:08:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-scipt/m-p/2102174#M90063</guid>
      <dc:creator>cristianj23a</dc:creator>
      <dc:date>2023-08-03T15:08:26Z</dc:date>
    </item>
  </channel>
</rss>

