<?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 can I calculate a cumulative sum in load script? in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333210#M705153</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think you can tell QlikView how to join tables directly so you have to get a bit sneaky about it. I think something like the following would work but it's untested...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tab1:&lt;/P&gt;&lt;P&gt;Load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Key1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Key2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Percentile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,etc&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;SQL Select * From Table1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INNER JOIN (Tab1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Key1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Key2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Percentile AS Percentile_T2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Metric1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Metric2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;SQL Select * From Table2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will join all rows where Key1 and Key2 both match. &lt;/P&gt;&lt;P&gt;Now you can group and sum, but judging by your query above you only want to do this where Percentile &amp;gt;= Percentile2, so:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LEFT JOIN (Tab1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Key1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Key2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Percentile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Sum(Metric1) AS Accum1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Sum(Metric2) AS Accum2&lt;/P&gt;&lt;P&gt;RESIDENT Tab1&lt;/P&gt;&lt;P&gt;WHERE Percentile &amp;gt;= Percentile2&lt;/P&gt;&lt;P&gt;GROUP BY Key1, Key2, Percentile;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think that might get you close...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Apr 2012 22:17:26 GMT</pubDate>
    <dc:creator>Jason_Michaelides</dc:creator>
    <dc:date>2012-04-02T22:17:26Z</dc:date>
    <item>
      <title>How can I calculate a cumulative sum in load script?</title>
      <link>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333209#M705152</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a (large) dataset being loaded from text with a composite key and several metric columns. I would like to include a cumulative sum (similar to "full aggregation" in a visualization, but the full aggregation option does not allow me to perform all the calculations and interactions I need).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The general structure of the dataset is:&lt;/P&gt;&lt;P&gt;key1, key2, ... : identifiers for this grouping&lt;/P&gt;&lt;P&gt;percentile : 10 values per key 10, 20, ..., 100&lt;/P&gt;&lt;P&gt;metric1, metric2 : counts of interactions in each percentile block that I would like to aggregate&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I were doing this in sql, I would do it as a self-join -- ex:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="sql" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;select t1.key1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;, t1.key2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;, t1.percentile&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;, sum(t2.metric1) as cum_sum_metric1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;, sum(t2.metric2) as cum_sum_metric2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;from table t1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;inner join table t2 &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;on t1.key1=t2.key1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;and t1.key2=t2.key2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;and t1.percentile &amp;gt;= t2.percentile&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;group by t1.key1&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;, t1.key2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: 'andale mono', times;"&gt;, t1.percentile&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to replicate this behavior in the Qlikview load script? Alternatively, if there is another way to accomplish this end, I am open to other suggestions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;--Matt&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 20:34:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333209#M705152</guid>
      <dc:creator />
      <dc:date>2012-04-02T20:34:02Z</dc:date>
    </item>
    <item>
      <title>How can I calculate a cumulative sum in load script?</title>
      <link>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333210#M705153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think you can tell QlikView how to join tables directly so you have to get a bit sneaky about it. I think something like the following would work but it's untested...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tab1:&lt;/P&gt;&lt;P&gt;Load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Key1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Key2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Percentile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,etc&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;SQL Select * From Table1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;INNER JOIN (Tab1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Key1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Key2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Percentile AS Percentile_T2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Metric1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Metric2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;SQL Select * From Table2;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will join all rows where Key1 and Key2 both match. &lt;/P&gt;&lt;P&gt;Now you can group and sum, but judging by your query above you only want to do this where Percentile &amp;gt;= Percentile2, so:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LEFT JOIN (Tab1)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; Key1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Key2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Percentile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Sum(Metric1) AS Accum1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ,Sum(Metric2) AS Accum2&lt;/P&gt;&lt;P&gt;RESIDENT Tab1&lt;/P&gt;&lt;P&gt;WHERE Percentile &amp;gt;= Percentile2&lt;/P&gt;&lt;P&gt;GROUP BY Key1, Key2, Percentile;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think that might get you close...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jason&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 22:17:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333210#M705153</guid>
      <dc:creator>Jason_Michaelides</dc:creator>
      <dc:date>2012-04-02T22:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate a cumulative sum in load script?</title>
      <link>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333211#M705154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Matt,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load your data into a table (lowest level of granularity).&lt;/P&gt;&lt;P&gt;Then aggregate using a Resident table.&lt;/P&gt;&lt;P&gt;i.e.:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Tbl:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Load index, Cum1, Cum2, ...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;From File1.qvd (qvd);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Tbl2:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;noconcatenate&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Load Index, Sum(Cum1) as Cum1, Sum(Cum2) as Cum2, ...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Resident &lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Tbl &lt;/SPAN&gt;group by index;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Drop Table Tbl; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 8pt;"&gt;Exit Script;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-size: 10pt;"&gt;Unless you are trying to get an incremental aggregation, then use Excel (i.e. b2 = b1 + a2, b3= b2 + a3, etc.)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-size: 10pt;"&gt;Regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 22:19:31 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333211#M705154</guid>
      <dc:creator />
      <dc:date>2012-04-02T22:19:31Z</dc:date>
    </item>
    <item>
      <title>How can I calculate a cumulative sum in load script?</title>
      <link>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333212#M705155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Use this sample script to find Cumulative Sum in script&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TableName:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F2,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RangeSum(F2, Peek('CumSum')) AS CumSum;&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F1, F2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a, 100&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b, 200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c, 300&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; d, 400&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jagan.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Apr 2012 05:17:26 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333212#M705155</guid>
      <dc:creator>jagan</dc:creator>
      <dc:date>2012-04-03T05:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I calculate a cumulative sum in load script?</title>
      <link>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333213#M705157</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Jagan,&amp;nbsp; A very useful tip.&amp;nbsp;&amp;nbsp; Just in case anyone is interested I have extened this to give me cumulative subtotals based on changes in F1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data:&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F1, F2, F3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a, 1,100&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a, 2,200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b, 1,3000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b, 2,4000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c, 1,40000&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; c, 2,40000&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;TableName:&lt;/P&gt;&lt;P&gt;Result:&lt;/P&gt;&lt;P&gt;NoConcatenate&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F2,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; F3,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; RangeSum(F3, Peek('CumAll')) as CumAll,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(F1&amp;lt;&amp;gt; previous(F1),F3,RangeSum(F3, Peek('CumF1'))) AS CumF1&lt;/P&gt;&lt;P&gt;RESIDENT Data;&lt;/P&gt;&lt;P&gt;DROP TABLE Data;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found you need to be careful about the preceeding load so have done it in two passes - It worked for me on a real fife problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Sep 2012 11:34:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/How-can-I-calculate-a-cumulative-sum-in-load-script/m-p/333213#M705157</guid>
      <dc:creator>philip_doyne</dc:creator>
      <dc:date>2012-09-01T11:34:46Z</dc:date>
    </item>
  </channel>
</rss>

