<?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 How to create a new column with accumulate sum in loading script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1858973#M1216034</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know how can I create a new column with accumulated transaction amount in loading script? I wanna create the table in data model. Please see the below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The existing table has three columns, which are Customer Name, Order Date, and Transaction Amount&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tonytang_0-1636824003363.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/66595i9A4FDA9E365A8CB6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tonytang_0-1636824003363.png" alt="tonytang_0-1636824003363.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now, I want to create a new column called "Accumulated Transaction amount", which is calculated on the Customer Level and&amp;nbsp; Year(Order date Level). Please see my expected output below&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tonytang_1-1636824529900.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/66596i5CE6F91DA6DF5867/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tonytang_1-1636824529900.png" alt="tonytang_1-1636824529900.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The transaction amount will keep accumulated until the year is changed to new year or the existing customer is changed to next customer name. For example, the first customer as above is accumulated from 4233 to 4275 in 2009, but once the year is updated to 2010, then the accumulated transaction amount will be reset to zero and then it will be accumulated again for every transaction amount in 2010. The value highlighted in red means the accumulated value is reset.&lt;/P&gt;
&lt;P&gt;I would like to create this table with 4 columns in the loading script . From my initial thoughts, it may be accomplished with using Autogenerate or Do-loop function, but i am unable to think of a way to resolve it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could everyone can give me some help? I am struggling for a few days.&lt;/P&gt;
&lt;P&gt;Thanks so much in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 13 Nov 2021 17:32:30 GMT</pubDate>
    <dc:creator>tonytang</dc:creator>
    <dc:date>2021-11-13T17:32:30Z</dc:date>
    <item>
      <title>How to create a new column with accumulate sum in loading script</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1858973#M1216034</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know how can I create a new column with accumulated transaction amount in loading script? I wanna create the table in data model. Please see the below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The existing table has three columns, which are Customer Name, Order Date, and Transaction Amount&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tonytang_0-1636824003363.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/66595i9A4FDA9E365A8CB6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tonytang_0-1636824003363.png" alt="tonytang_0-1636824003363.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now, I want to create a new column called "Accumulated Transaction amount", which is calculated on the Customer Level and&amp;nbsp; Year(Order date Level). Please see my expected output below&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="tonytang_1-1636824529900.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/66596i5CE6F91DA6DF5867/image-size/medium?v=v2&amp;amp;px=400" role="button" title="tonytang_1-1636824529900.png" alt="tonytang_1-1636824529900.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The transaction amount will keep accumulated until the year is changed to new year or the existing customer is changed to next customer name. For example, the first customer as above is accumulated from 4233 to 4275 in 2009, but once the year is updated to 2010, then the accumulated transaction amount will be reset to zero and then it will be accumulated again for every transaction amount in 2010. The value highlighted in red means the accumulated value is reset.&lt;/P&gt;
&lt;P&gt;I would like to create this table with 4 columns in the loading script . From my initial thoughts, it may be accomplished with using Autogenerate or Do-loop function, but i am unable to think of a way to resolve it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could everyone can give me some help? I am struggling for a few days.&lt;/P&gt;
&lt;P&gt;Thanks so much in advance&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Nov 2021 17:32:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1858973#M1216034</guid>
      <dc:creator>tonytang</dc:creator>
      <dc:date>2021-11-13T17:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new column with accumulate sum in loading script</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859043#M1216038</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;one solution might be:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="QlikCommunity_Thread_t5_QlikView-App-Dev_How-to-create-a-new-column-with-accumulate-sum-in-loading-script_m-p_1858973_Pic1.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/66606i9DD99F269138A174/image-size/medium?v=v2&amp;amp;px=400" role="button" title="QlikCommunity_Thread_t5_QlikView-App-Dev_How-to-create-a-new-column-with-accumulate-sum-in-loading-script_m-p_1858973_Pic1.png" alt="QlikCommunity_Thread_t5_QlikView-App-Dev_How-to-create-a-new-column-with-accumulate-sum-in-loading-script_m-p_1858973_Pic1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;table1:
LOAD 'Customer'&amp;amp;Ceil(Rand()*5)		as CustomerName,
     Dayname(Today()-Rand()*1500)	as OrderDate,
     Ceil(Rand()*1000)				as TransactionAmount
AutoGenerate 100;


table2:
LOAD *,
     RangeSum(TransactionAmount,If(CustomerName=Previous(CustomerName) and Year(OrderDate)=Previous(Year(OrderDate)),Peek(AccumulatedTransactionAmount))) as AccumulatedTransactionAmount
Resident table1
Order By CustomerName, OrderDate;


DROP Table table1;&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;hope this helps&lt;/P&gt;
&lt;P&gt;Marco&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 12:35:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859043#M1216038</guid>
      <dc:creator>MarcoWedel</dc:creator>
      <dc:date>2021-11-14T12:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new column with accumulate sum in loading script</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859046#M1216039</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Maybe below script can help. I have created a sample dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table:&lt;BR /&gt;Load Customer,Date(Date#(Date,'D/MM/YYYY')) as Date, Amount Inline [&lt;BR /&gt;Customer,Date,Amount&lt;BR /&gt;AB,1/7/2009,4233&lt;BR /&gt;AB,7/7/2009,42&lt;BR /&gt;AB,27/7/2010,5002&lt;BR /&gt;AB,9/11/2010,2337&lt;BR /&gt;AB,28/5/2010,14&lt;BR /&gt;AH,15/8/2009,460&lt;BR /&gt;AH,13/12/2009,13255&lt;/P&gt;
&lt;P&gt;];&lt;/P&gt;
&lt;P&gt;Table1:&lt;BR /&gt;Load * ,&lt;BR /&gt;&lt;STRONG&gt;If(Customer = Previous(Customer) and Year(Date)=Previous(Year(Date)),&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;RangeSum(Peek(Accumulated_Amount), Amount),Amount) as Accumulated_Amount&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Resident Table Order by Customer,Date;&lt;BR /&gt;Drop Table Table;&lt;/P&gt;
&lt;P&gt;Output :&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AshutoshBhumkar_0-1636894017824.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/66607i7DE42F1BBA841919/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AshutoshBhumkar_0-1636894017824.png" alt="AshutoshBhumkar_0-1636894017824.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Ashutosh&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 12:47:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859046#M1216039</guid>
      <dc:creator>AshutoshBhumkar</dc:creator>
      <dc:date>2021-11-14T12:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new column with accumulate sum in loading script</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859060#M1216045</link>
      <description>&lt;P&gt;Thanks both. It works.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Nov 2021 16:16:39 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859060#M1216045</guid>
      <dc:creator>tonytang</dc:creator>
      <dc:date>2021-11-14T16:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new column with accumulate sum in loading script</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859587#M1216070</link>
      <description>&lt;P&gt;you're welcome&lt;/P&gt;</description>
      <pubDate>Mon, 15 Nov 2021 20:37:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859587#M1216070</guid>
      <dc:creator>MarcoWedel</dc:creator>
      <dc:date>2021-11-15T20:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a new column with accumulate sum in loading script</title>
      <link>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859684#M1216073</link>
      <description>&lt;P&gt;Great &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Nov 2021 05:34:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-to-create-a-new-column-with-accumulate-sum-in-loading-script/m-p/1859684#M1216073</guid>
      <dc:creator>AshutoshBhumkar</dc:creator>
      <dc:date>2021-11-16T05:34:33Z</dc:date>
    </item>
  </channel>
</rss>

