<?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 column in script using loop in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Cumulative-column-in-script-using-loop/m-p/743961#M665099</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, If you load SKUSegmentation with 'NoConcatenate' it will create a table for each different vMarketNo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before the bucle you can create an (almost) empty inline table and concatente values in this table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SKUSegmentation: LOAD * Inline [DumbField];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;SKUSegmentation:&lt;/P&gt;&lt;P&gt;Concatenate (SKUSegmentation)&lt;/P&gt;&lt;P&gt;LOAD ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I usually do this kind of cummulative sum without a bucle, I use a order by clause and peek() to check when a new market starts, I don't know wich one gets better performance:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SKUSegmentation:&lt;/P&gt;&lt;P&gt;LOAD ...&lt;/P&gt;&lt;P&gt;If(Peek(%SegmentationMarket)=%SegmentationMarket, RangeSum(SKUVol...), SKUVolume) as CumulativeVol,&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;order by %SegmentationMarket, SKUVolume desc;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Jan 2015 16:02:07 GMT</pubDate>
    <dc:creator>rubenmarin</dc:creator>
    <dc:date>2015-01-21T16:02:07Z</dc:date>
    <item>
      <title>Cumulative column in script using loop</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-column-in-script-using-loop/m-p/743960#M665098</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to create a table of products with a cumulative volume column. I have done this in my script successfully for the entire loaded data set, but now need to modify my script to account for multiple markets. The cumulative volume column should be &lt;EM&gt;per market&lt;/EM&gt;, not based on overall volume. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is my script so far, though I am struggling with the correct syntax for the loop &lt;SPAN style="color: #ff0000;"&gt;(red font below)&lt;/SPAN&gt;, please can anyone advise?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Load in all volume&lt;/P&gt;&lt;P&gt;[SKU Segmentation-1]:&lt;/P&gt;&lt;P&gt;LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; [Market] as %SegmentationMarket,&lt;/P&gt;&lt;P&gt;&amp;nbsp; [SKU Number] as %SKU,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum([Actual Volume (HL) W+1]) as [SKUVolume-1],&lt;/P&gt;&lt;P&gt;&amp;nbsp; [Week Start Date]&lt;/P&gt;&lt;P&gt;FROM&lt;/P&gt;&lt;P&gt;[PlanningAnalyticsData.xlsm]&lt;/P&gt;&lt;P&gt;(ooxml, embedded labels, table is [Demand - W+1])&lt;/P&gt;&lt;P&gt;WHERE [Actual Volume (HL) W+1] &amp;gt;='0' AND ([Actual Volume (HL) W+1] &amp;lt;&amp;gt; '0' OR [Forecasted Volume (HL) W+1] &amp;lt;&amp;gt; '0') &lt;/P&gt;&lt;P&gt;group by [Market], [SKU Number], [Week Start Date]&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Define 52 week parameter&lt;/P&gt;&lt;P&gt;Temp:&lt;/P&gt;&lt;P&gt;LOAD max([Week Start Date])-365 as mini, max([Week Start Date]) as maxi resident [SKU Segmentation-1];&lt;/P&gt;&lt;P&gt;Let vMaxWeekStartDateLessOneYear = peek('mini',0,'Temp');&lt;/P&gt;&lt;P&gt;Let vMaxWeekStartDate = peek('maxi',0,'Temp');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;drop table Temp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Total volume per market&lt;/P&gt;&lt;P&gt;[Market List]:&lt;/P&gt;&lt;P&gt;LOAD distinct&lt;/P&gt;&lt;P&gt;%SegmentationMarket,&lt;/P&gt;&lt;P&gt;sum([SKUVolume-1]) as [MostRecentYear_TotalVol_Master]&lt;/P&gt;&lt;P&gt;resident [SKU Segmentation-1]&lt;/P&gt;&lt;P&gt;where [Week Start Date] &amp;gt;= $(vMaxWeekStartDateLessOneYear) AND [Week Start Date] &amp;lt;= $(vMaxWeekStartDate)&lt;/P&gt;&lt;P&gt;group by %SegmentationMarket;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Market_to_TotalVol:&lt;/P&gt;&lt;P&gt;MAPPING LOAD&lt;/P&gt;&lt;P&gt;&amp;nbsp; [%SegmentationMarket],&lt;/P&gt;&lt;P&gt;&amp;nbsp; [MostRecentYear_TotalVol_Master]&lt;/P&gt;&lt;P&gt;resident&lt;/P&gt;&lt;P&gt;[Market List];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//Restrict volume to last 52 weeks&lt;/P&gt;&lt;P&gt;[SKU Segmentation]:&lt;/P&gt;&lt;P&gt;LOAD %SegmentationMarket,&lt;/P&gt;&lt;P&gt;&amp;nbsp; %SKU,&lt;/P&gt;&lt;P&gt;&amp;nbsp; sum([SKUVolume-1]) as SKUVolume,&lt;/P&gt;&lt;P&gt;&amp;nbsp; ApplyMap('Market_to_TotalVol',%SegmentationMarket,null()) as [MostRecentYear_TotalVol]&lt;/P&gt;&lt;P&gt;resident [SKU Segmentation-1]&lt;/P&gt;&lt;P&gt;where [Week Start Date] &amp;gt;= $(vMaxWeekStartDateLessOneYear) AND [Week Start Date] &amp;lt;= $(vMaxWeekStartDate)&lt;/P&gt;&lt;P&gt;group by %SegmentationMarket, %SKU;&lt;/P&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;&lt;P&gt;drop table [SKU Segmentation-1];&lt;/P&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;&lt;P&gt;&amp;nbsp; [MarketList]:&lt;/P&gt;&lt;P&gt;&amp;nbsp; load&lt;/P&gt;&lt;P&gt;&amp;nbsp; %SegmentationMarket&lt;/P&gt;&lt;P&gt;&amp;nbsp; resident [Market List];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop table [Market List];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; for vMarketNo = 1 to NoOfRows('MarketList')&lt;/P&gt;&lt;P&gt;&amp;nbsp; let vMarketName = peek(%SegmentationMarket,vMarketNo-1,'MarketList');&lt;/P&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;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;//Create cumulative column for descending volume, per market&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; [SKUSegmentation]:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; noconcatenate LOAD &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; %SegmentationMarket, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; %SKU, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; SKUVolume,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; RangeSum(SKUVolume, Peek('CumulativeVol')) as CumulativeVol,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; MostRecentYear_TotalVol&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; resident [SKU Segmentation]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; where %SegmentationMarket = '$(vMarketName)'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; order by SKUVolume desc;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; next vMarketNo&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; drop table [SKU Segmentation];&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jan 2015 15:19:59 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-column-in-script-using-loop/m-p/743960#M665098</guid>
      <dc:creator />
      <dc:date>2015-01-21T15:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative column in script using loop</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-column-in-script-using-loop/m-p/743961#M665099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, If you load SKUSegmentation with 'NoConcatenate' it will create a table for each different vMarketNo.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before the bucle you can create an (almost) empty inline table and concatente values in this table:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SKUSegmentation: LOAD * Inline [DumbField];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For...&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;SKUSegmentation:&lt;/P&gt;&lt;P&gt;Concatenate (SKUSegmentation)&lt;/P&gt;&lt;P&gt;LOAD ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, I usually do this kind of cummulative sum without a bucle, I use a order by clause and peek() to check when a new market starts, I don't know wich one gets better performance:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SKUSegmentation:&lt;/P&gt;&lt;P&gt;LOAD ...&lt;/P&gt;&lt;P&gt;If(Peek(%SegmentationMarket)=%SegmentationMarket, RangeSum(SKUVol...), SKUVolume) as CumulativeVol,&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;order by %SegmentationMarket, SKUVolume desc;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jan 2015 16:02:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-column-in-script-using-loop/m-p/743961#M665099</guid>
      <dc:creator>rubenmarin</dc:creator>
      <dc:date>2015-01-21T16:02:07Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative column in script using loop</title>
      <link>https://community.qlik.com/t5/QlikView/Cumulative-column-in-script-using-loop/m-p/743962#M665100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ruben,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for the response - incredibly helpful and timely!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second option works brilliantly, and performance seems great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jan 2015 17:18:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Cumulative-column-in-script-using-loop/m-p/743962#M665100</guid>
      <dc:creator />
      <dc:date>2015-01-21T17:18:16Z</dc:date>
    </item>
  </channel>
</rss>

