<?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: Running Total Calculation Considering Previous Row in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Running-Total-Calculation-Considering-Previous-Row/m-p/1550570#M39678</link>
    <description>&lt;P&gt;That is perfect.&amp;nbsp; I was trying to jam it all into one load not thinking about using preceding load(s).&amp;nbsp; Thank you so much!&lt;/P&gt;</description>
    <pubDate>Thu, 28 Feb 2019 14:44:33 GMT</pubDate>
    <dc:creator>carlcimino</dc:creator>
    <dc:date>2019-02-28T14:44:33Z</dc:date>
    <item>
      <title>Running Total Calculation Considering Previous Row</title>
      <link>https://community.qlik.com/t5/App-Development/Running-Total-Calculation-Considering-Previous-Row/m-p/1550132#M39643</link>
      <description>&lt;P&gt;Hello I am trying to add something like a running total that takes the a calculation on the previous row into consideration for the current row.&amp;nbsp; Here is my sample data and what I have tried to use.&amp;nbsp;&lt;/P&gt;&lt;P&gt;RATE_DATA_TEMP:&lt;/P&gt;&lt;P&gt;Load * inline [&lt;/P&gt;&lt;P&gt;RATE_KEY, Check, ROWID, ACTUAL_RATE_CHANGE, STAT_WP&lt;BR /&gt;13413, 0.00, 56, 0.075, 5,532.00,&lt;BR /&gt;13413, 1.00, 57, 0.052, 5,532.00,&lt;BR /&gt;13413, 1.00, 58, 0.024, 5,532.00,&lt;BR /&gt;]&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;RATE_DATA:&lt;BR /&gt;load *,&lt;BR /&gt;if(RATE_KEY=previous(RATE_KEY),&lt;/P&gt;&lt;P&gt;(&lt;BR /&gt;(peek('ACTUAL_RATE_CHANGE')*peek('STAT_WP'))+peek('STAT_WP')) +&lt;BR /&gt;&lt;BR /&gt;((peek('ACTUAL_RATE_CHANGE')*peek('STAT_WP'))+peek('STAT_WP'))*[ACTUAL_RATE_CHANGE],&lt;BR /&gt;&lt;BR /&gt;([STAT_WP]*[ACTUAL_RATE_CHANGE])+[STAT_WP]) as STAT_WP_NEW,&lt;/P&gt;&lt;P&gt;resident RATE_DATA_TEMP;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;drop table RATE_DATA_TEMP;&lt;/P&gt;&lt;P&gt;I've attached a file showing how it is done in excel and how I would like it to look.&amp;nbsp; The dollar_change field comes from the result of the prior rows new_stat_wp * the current rows ACTUAL_RATE_CHANGE.&amp;nbsp; The&amp;nbsp;new_stat_wp is then the sum of that plus the current row dollar_change.&lt;/P&gt;&lt;P&gt;RATE_KEY, Check, ROWID, ACTUAL_RATE_CHANGE, STAT_WP,dollar_change, new_stat_wp&lt;BR /&gt;13413, 0.00, 56, 0.075, 5,532.00, 414.90, 5,946.90,&lt;BR /&gt;13413, 1.00, 57, 0.052, 5,532.00, 309.24, 6,256.14,&lt;BR /&gt;13413, 1.00, 58, 0.024, 5,532.00, 150.15, 6,406.29,&lt;/P&gt;&lt;P&gt;Any help would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 21:19:53 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Running-Total-Calculation-Considering-Previous-Row/m-p/1550132#M39643</guid>
      <dc:creator>carlcimino</dc:creator>
      <dc:date>2024-11-16T21:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Running Total Calculation Considering Previous Row</title>
      <link>https://community.qlik.com/t5/App-Development/Running-Total-Calculation-Considering-Previous-Row/m-p/1550154#M39645</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Shortly:&lt;/P&gt;&lt;P&gt;first of all you need to handle "first" occurrence of your RATE_KEY and apply corresponding formula (like you did in Excel - it's different to the rest) and create these new fields; = exactly what's happening in "first preceding load"&lt;/P&gt;&lt;P&gt;secondly, you need to apply your new formula to the rows with the same RATE_KEY; = exactly what's happening in the "second preceding load" (with some math simplification applied)&lt;/P&gt;&lt;P&gt;Please check below script:&lt;/P&gt;&lt;P&gt;RATE_DATA:&lt;/P&gt;&lt;P&gt;//Second preceding load below&lt;BR /&gt;LOAD RATE_KEY&lt;BR /&gt;, Check&lt;BR /&gt;, ROWID&lt;BR /&gt;, ACTUAL_RATE_CHANGE&lt;BR /&gt;, STAT_WP&lt;BR /&gt;, IF( RATE_KEY = PEEK(RATE_KEY),&lt;BR /&gt;ACTUAL_RATE_CHANGE*PEEK(NEW_STAT_WP),&lt;BR /&gt;DOLLAR_CHANGE&lt;BR /&gt;) AS DOLLAR_CHANGE&lt;BR /&gt;, IF( RATE_KEY = PEEK(RATE_KEY),&lt;BR /&gt;PEEK(NEW_STAT_WP)*(1+ACTUAL_RATE_CHANGE),&lt;BR /&gt;NEW_STAT_WP&lt;BR /&gt;) AS NEW_STAT_WP&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;//First preceding load below&lt;/P&gt;&lt;P&gt;LOAD *,&lt;BR /&gt;IF( RATE_KEY &amp;lt;&amp;gt; PEEK(RATE_KEY),&lt;BR /&gt;STAT_WP*ACTUAL_RATE_CHANGE) AS DOLLAR_CHANGE,&lt;BR /&gt;IF( RATE_KEY &amp;lt;&amp;gt; PEEK(RATE_KEY),&lt;BR /&gt;STAT_WP*(1+ACTUAL_RATE_CHANGE)) AS NEW_STAT_WP&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;Load * inline [&lt;BR /&gt;RATE_KEY, Check, ROWID, ACTUAL_RATE_CHANGE, STAT_WP&lt;BR /&gt;13413, 0.00, 56, 0.075, 5532.00,&lt;BR /&gt;13413, 1.00, 57, 0.052, 5532.00,&lt;BR /&gt;13413, 1.00, 58, 0.024, 5532.00,&lt;BR /&gt;]&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please NOTE that when you're using PEEK() function sorting is crucial and if you change a sort order - results will be entirely different.&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;//Andrei&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="M39643.PNG" style="width: 727px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/6919i872EF5CFC28D3CD1/image-size/large?v=v2&amp;amp;px=999" role="button" title="M39643.PNG" alt="M39643.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 00:14:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Running-Total-Calculation-Considering-Previous-Row/m-p/1550154#M39645</guid>
      <dc:creator>crusader_</dc:creator>
      <dc:date>2019-02-28T00:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Running Total Calculation Considering Previous Row</title>
      <link>https://community.qlik.com/t5/App-Development/Running-Total-Calculation-Considering-Previous-Row/m-p/1550570#M39678</link>
      <description>&lt;P&gt;That is perfect.&amp;nbsp; I was trying to jam it all into one load not thinking about using preceding load(s).&amp;nbsp; Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Feb 2019 14:44:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Running-Total-Calculation-Considering-Previous-Row/m-p/1550570#M39678</guid>
      <dc:creator>carlcimino</dc:creator>
      <dc:date>2019-02-28T14:44:33Z</dc:date>
    </item>
  </channel>
</rss>

