<?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 12 months Sum on load script in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560890#M689432</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Telmo, that's a tricky one!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have 3 options:&lt;/P&gt;&lt;P&gt;1) Complete the months in the table using dummy month numbers (easiest way to do this would be an outer join on a straight list of months)&lt;/P&gt;&lt;P&gt;2) Completely different method- use "intervalmatch" to join the table onto itself using an interval of Month, and month -12. Then group by month and sum by all the sales of the joined table (not recommended as you will end up with a datset 12 X bigger)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or 3) join in any month -12 's that dont exist, and vice versa. Infact all you have to do to achieve this is change the bit where you join the Month-12 in to an outer join- which will fill in the blanks for you:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Add in the previous 12 months total8/&lt;/P&gt;&lt;P&gt;outer join (GenData) Load Cat1, Cat2,&amp;nbsp; Month + 12 as Month , Month&amp;nbsp; as MonthL12, Sales as SalesL12 resident GenData;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erica&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Nov 2013 23:02:06 GMT</pubDate>
    <dc:creator />
    <dc:date>2013-11-05T23:02:06Z</dc:date>
    <item>
      <title>Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560881#M689423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to create a cumulative 12 months Sum(Revenue) on the load script, &lt;STRONG style="text-decoration: underline;"&gt;aggregated by month, category and reseller&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Meaning that for each month, the sum should be based on up to the 12 previous months. &lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" width="221"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="64"&gt;Month&lt;/TD&gt;&lt;TD width="64"&gt;Revenue&lt;/TD&gt;&lt;TD width="93"&gt;Cumulative12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Jan-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Feb-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;20&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Mar-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;30&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Apr-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;40&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;May-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;50&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Jun-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Jul-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;70&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Aug-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;80&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Sep-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;90&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Oct-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Nov-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;110&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Dec-12&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Jan-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Feb-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Mar-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Apr-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;May-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Jun-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Jul-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Aug-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Sep-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD align="right" class="xl63" height="20"&gt;Oct-13&lt;/TD&gt;&lt;TD align="right"&gt;10&lt;/TD&gt;&lt;TD align="right"&gt;120&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The table contains many fields but I want the cumulative12 Sum, that will be used for banding, to be aggregated by &lt;STRONG style="text-decoration: underline;"&gt;month, category and&amp;nbsp; reseller.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a look at rangesum and peek not sure it will work here. I think it can be achieve with joins and group by.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 15:45:05 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560881#M689423</guid>
      <dc:creator>tduarte</dc:creator>
      <dc:date>2013-11-01T15:45:05Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560882#M689424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Rangesum and peek will work, but it's going to be quite an expression:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;rangesum(Revenue, peek(Revenue), peek(Revenue, -2), peek(Revenue,-3), ...etc... , peek(Revenue,-11)) as Cumulative12&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Perhaps an AsOf table is a better approach in this case. See this document: &lt;A _jive_internal="true" href="https://community.qlik.com/docs/DOC-4252" style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3778c7;"&gt;Calculating rolling n-period totals, averages or other aggregations&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Nov 2013 16:38:41 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560882#M689424</guid>
      <dc:creator>Gysbert_Wassenaar</dc:creator>
      <dc:date>2013-11-01T16:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560883#M689425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Telmo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A simple solution would be to join on the revenue data for the single month 12 months previously, then cumulatively subtract at the sane time as the cumulative sum. This example will run by itself in a script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//Generated Sales Data&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;GenData:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;load rowno() as Month, round(rand()*100) as Sales autogenerate(36);&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//Add in sales from the same table, as they were 12 months ago&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;left join (GenData) Load&amp;nbsp; Month + 12 as Month , Month&amp;nbsp; as MonthL12, Sales as SalesL12 resident GenData;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//Do the usual cumulative sum - but minus the value from 12 months ago&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;left join (GenData) Load Month,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;numsum(Sales,Peek(CumSum) ) as CumSum,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;numsum(Sales,Peek(CumSumL12) ,-SalesL12 ) as CumSumL12&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; resident GenData;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erica&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Nov 2013 19:28:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560883#M689425</guid>
      <dc:creator />
      <dc:date>2013-11-02T19:28:46Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560884#M689426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi G Wassenaar,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An AsOf table was my initial design but due to poor performance in the pivot table I need to try and create the cumulative revenues and the corresponding bands in the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Rangesum didn't work for me because I need to group it by several dimensions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 12:41:09 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560884#M689426</guid>
      <dc:creator>tduarte</dc:creator>
      <dc:date>2013-11-04T12:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560885#M689427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Erica,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I had a go using your suggestion and it's more or less what I was looking for but unfortunately the cumulative sums are incorrect because these are not aggregating by my other 2 fields, reseller and category.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is what I've done:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Banding:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Load&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; MonthStartDate as Banding.Date,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; Category as Banding.Category,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; ResellerID as Banding.ResellerID,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; Sum(Revenue) as Banding.Revenue&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Resident Data&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Group by MonthStartDate, Category, ResellerID;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//Add in sales from the same table, as they were 12 months ago&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Left Join (Banding)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Load&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; AddMonths(Banding.Date,12) as Banding.Date,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; Banding.Category,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; Banding.ResellerID,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; Banding.Date as Banding.DateL12,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; Banding.Revenue as Banding.RevenueL12&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Resident Banding;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//Do the usual cumulative sum - but minus the value from 12 months ago&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Left Join (Banding)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Load&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; Banding.Date,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; Banding.Category,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; Banding.ResellerID,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; numsum(Banding.Revenue,Peek(CumSum)) as CumSum,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; numsum(Banding.Revenue,Peek(CumSumL12) ,-Banding.RevenueL12) as CumSumL12&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Resident Banding;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Telmo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 15:39:38 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560885#M689427</guid>
      <dc:creator>tduarte</dc:creator>
      <dc:date>2013-11-04T15:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560886#M689428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Telmo&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You need to check that the Category and reseller in the row above are the same as the current row, before applying the cumulative sum. In this simplified example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//Do the usual cumulative sum - but minus the value from 12 months ago&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;left join (GenData) Load Cat1, Cat2, Month, &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;if(Peek(Cat1)&amp;amp;peek(Cat2) = Cat1&amp;amp;Cat2,&amp;nbsp;&amp;nbsp;&amp;nbsp; numsum(Sales,Peek(CumSum) ),0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as CumSum,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;if(Peek(Cat1)&amp;amp;peek(Cat2) = Cat1&amp;amp;Cat2,&amp;nbsp;&amp;nbsp;&amp;nbsp; numsum(Sales,Peek(CumSumL12) ,-SalesL12 ),0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as CumSumL12&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; resident GenData;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've used the peek function again to verify that we are still in the same category as the row above, before adding the sales to the cumulative sum function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erica&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 21:58:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560886#M689428</guid>
      <dc:creator />
      <dc:date>2013-11-04T21:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560887#M689429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PS this full script will work on its own and serve as a test:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Generate Categories:&lt;/P&gt;&lt;P&gt;GenData:&lt;/P&gt;&lt;P&gt;LOAD * INLINE [&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cat1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Birmingham&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; London&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Newcastle&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Manchester&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Liverpool&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bristol&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bath&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bournemouth&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Left join (GenData) LOAD * INLINE [&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Cat2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bananas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Olives&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Apples&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Celery&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Lettuce&lt;/P&gt;&lt;P&gt;];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;//Add in the months&lt;/P&gt;&lt;P&gt;Left join (GenData)load rowno() as Month autogenerate(36);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Add in random sales data&lt;/P&gt;&lt;P&gt;Left join (GenData) Load Cat1, Cat2, Month, round(rand()*100) as Sales resident GenData;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Add in the previous 12 months total8/&lt;/P&gt;&lt;P&gt;left join (GenData) Load Cat1, Cat2,&amp;nbsp; Month + 12 as Month , Month&amp;nbsp; as MonthL12, Sales as SalesL12 resident GenData;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Do the usual cumulative sum - but minus the value from 12 months ago&lt;/P&gt;&lt;P&gt;left join (GenData) Load Cat1, Cat2, Month, &lt;/P&gt;&lt;P&gt;if(Peek(Cat1)&amp;amp;peek(Cat2) = Cat1&amp;amp;Cat2,&amp;nbsp;&amp;nbsp;&amp;nbsp; numsum(Sales,Peek(CumSum) ),0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as CumSum,&lt;/P&gt;&lt;P&gt;if(Peek(Cat1)&amp;amp;peek(Cat2) = Cat1&amp;amp;Cat2,&amp;nbsp;&amp;nbsp;&amp;nbsp; numsum(Sales,Peek(CumSumL12) ,-SalesL12 ),0)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as CumSumL12&lt;/P&gt;&lt;P&gt;&amp;nbsp; resident GenData;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Nov 2013 21:58:40 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560887#M689429</guid>
      <dc:creator />
      <dc:date>2013-11-04T21:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560888#M689430</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Erica,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So this mean that the only way of making it work is to do an Order By ResellerID, Category and Month - Month needs to be the last -&amp;nbsp; before doing the Peek / cumulative sum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess I was hoping there would be a different way.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2013 10:05:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560888#M689430</guid>
      <dc:creator>tduarte</dc:creator>
      <dc:date>2013-11-05T10:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560889#M689431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The cumulative sum expression should be:&lt;/P&gt;&lt;P style="font-size: 12.727272033691406px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;if(Peek(Cat1)&amp;amp;peek(Cat2) = Cat1&amp;amp;Cat2,&amp;nbsp;&amp;nbsp; numsum(Sales,Peek(CumSum) ),&lt;STRONG&gt;Sales&lt;/STRONG&gt;) as CumSum,&lt;/EM&gt;&lt;/P&gt;&lt;P style="font-size: 12.727272033691406px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #3d3d3d;"&gt;&lt;EM&gt;if(Peek(Cat1)&amp;amp;peek(Cat2) = Cat1&amp;amp;Cat2,&amp;nbsp;&amp;nbsp; numsum(Sales,Peek(CumSumL12) ,-SalesL12 ),&lt;STRONG&gt;Sales&lt;/STRONG&gt;) as CumSumL12&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Otherwise the first row isn't taken into the sum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I just realized this still doesn't work because my data doesn't have all the Months for each Category/ResellerID combination. This means that not all Month have a Month + 12 and SalesL12 won't be added in the join. As a result the CumSumL12 ends up being higher than what it should.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The sum should be based on up to the 12 previous months but not necessarily 12 records.&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.PNG.png" class="jive-image" src="https://community.qlik.com/legacyfs/online/48546_Capture.PNG.png" /&gt;&lt;/P&gt;&lt;P&gt;For example, in 2012-10-01, the Cumulative 12 Months sum should be 3415.26.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any other ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2013 12:26:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560889#M689431</guid>
      <dc:creator>tduarte</dc:creator>
      <dc:date>2013-11-05T12:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560890#M689432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Telmo, that's a tricky one!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You have 3 options:&lt;/P&gt;&lt;P&gt;1) Complete the months in the table using dummy month numbers (easiest way to do this would be an outer join on a straight list of months)&lt;/P&gt;&lt;P&gt;2) Completely different method- use "intervalmatch" to join the table onto itself using an interval of Month, and month -12. Then group by month and sum by all the sales of the joined table (not recommended as you will end up with a datset 12 X bigger)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or 3) join in any month -12 's that dont exist, and vice versa. Infact all you have to do to achieve this is change the bit where you join the Month-12 in to an outer join- which will fill in the blanks for you:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Add in the previous 12 months total8/&lt;/P&gt;&lt;P&gt;outer join (GenData) Load Cat1, Cat2,&amp;nbsp; Month + 12 as Month , Month&amp;nbsp; as MonthL12, Sales as SalesL12 resident GenData;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erica&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Nov 2013 23:02:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560890#M689432</guid>
      <dc:creator />
      <dc:date>2013-11-05T23:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative 12 months Sum on load script</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560891#M689433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Erica,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Option 3 does the job but after I had to change the cumulative sum to a temp table then inner join it with the original one to remove records added with the outer that represented no sales:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//Add in the previous 12 months total&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;outer join (GenData) Load Cat1, Cat2,&amp;nbsp; Month + 12 as Month , Month&amp;nbsp; as MonthL12, Sales as SalesL12 resident GenData;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//Do the usual cumulative sum - but minus the value from 12 months ago&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;CumulativeTemp:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Load Cat1, Cat2, Month,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; if(Peek(Cat1)&amp;amp;peek(Cat2) = Cat1&amp;amp;Cat2, numsum(Sales,Peek(CumSum) ),Sales) as CumSum,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; if(Peek(Cat1)&amp;amp;peek(Cat2) = Cat1&amp;amp;Cat2, numsum(Sales,Peek(CumSumL12) ,-SalesL12 ),Sales) as CumSumL12,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp; if(not(isnull(Sales)),1) as IsActualSales&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;resident GenData;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;//Remove records where there were no actual sales (added with outer join for missing months)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Inner Join (GenData)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Load Cat1, Cat2, Month, CumSumL12&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Resident CumulativeTemp&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Where IsActualSales;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Drop Table CumulativeTemp;&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 07 Nov 2013 10:02:36 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-12-months-Sum-on-load-script/m-p/560891#M689433</guid>
      <dc:creator>tduarte</dc:creator>
      <dc:date>2013-11-07T10:02:36Z</dc:date>
    </item>
  </channel>
</rss>

