<?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 Sum in load script using Peek? in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490804#M102012</link>
    <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/180799"&gt;@110&lt;/a&gt;&amp;nbsp; it seems issue with Order by. I think order by should be like below&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;ORDER BY appId,CMLMonth,DateOnly;&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 05 Nov 2024 11:53:45 GMT</pubDate>
    <dc:creator>Kushal_Chawda</dc:creator>
    <dc:date>2024-11-05T11:53:45Z</dc:date>
    <item>
      <title>Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490777#M102000</link>
      <description>&lt;P&gt;So I wanted to roll up the entitlement consumption in the consumption monitor to see at what point in month we reached 50%/75% of our capcity.&lt;BR /&gt;&lt;BR /&gt;I'm just tacking this on the end so as not to interfere with the usual QVD incremental load, however it seems to be duplicating rows and not summing as expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I first create a table that sums the CapacityUsed by Date &amp;amp; AppID , then use Peek.&lt;/P&gt;
&lt;LI-CODE lang="ruby"&gt;[Cumulative]:

NoConcatenate

LOAD 
    appId,
    MonthStart( Date(Timestamp#(endTime, 'YYYY-MM-DDThh:mm:ss.fffZ'))) AS CMLMonth, 
    Date(Timestamp#(endTime, 'YYYY-MM-DDThh:mm:ss.fffZ')) AS DateOnly,  // Extracts date portion from endTime
    Sum(capacityUsed) AS TotalCapacityUsed

RESIDENT Entitlement_Consumption

GROUP BY appId, Date(Timestamp#(endTime, 'YYYY-MM-DDThh:mm:ss.fffZ')),  MonthStart( Date(Timestamp#(endTime, 'YYYY-MM-DDThh:mm:ss.fffZ')));


[MonthlyCumulative]:

NoConcatenate

LOAD
    appId,DateOnly as CMLDate,
    CMLMonth,
       // Get the month start for grouping by month
    If(CMLMonth = Peek('CMLMonth')AND appId = Peek('appId'),
        Peek('CumulativeCapacityUsed') + TotalCapacityUsed,TotalCapacityUsed) AS CumulativeCapacityUsed    // Calculate cumulative sum

RESIDENT [Cumulative]
ORDER BY DateOnly,appId, CMLMonth;


Drop Table Cumulative;

&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;What I should eventually get is akin to the below&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="110_0-1730804675267.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/173801iB416EB49EB9C4341/image-size/large?v=v2&amp;amp;px=999" role="button" title="110_0-1730804675267.png" alt="110_0-1730804675267.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However it doesn't seem to be accumulating&amp;nbsp;&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="110_1-1730804725457.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/173802iB464858F88EEBA27/image-size/large?v=v2&amp;amp;px=999" role="button" title="110_1-1730804725457.png" alt="110_1-1730804725457.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 11:05:54 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490777#M102000</guid>
      <dc:creator>110</dc:creator>
      <dc:date>2024-11-05T11:05:54Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490778#M102001</link>
      <description>&lt;P&gt;Whats your Cumulative Calc expression?&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 11:08:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490778#M102001</guid>
      <dc:creator>Qrishna</dc:creator>
      <dc:date>2024-11-05T11:08:32Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490779#M102002</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/180799"&gt;@110&lt;/a&gt;&amp;nbsp; try to use rangesum()&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;If(CMLMonth = Peek('CMLMonth')AND appId = Peek('appId'),
        rangesum(Peek('CumulativeCapacityUsed'),TotalCapacityUsed),TotalCapacityUsed) AS CumulativeCapacityUsed &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 11:14:03 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490779#M102002</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2024-11-05T11:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490802#M102011</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/41222"&gt;@Qrishna&lt;/a&gt;&amp;nbsp; &amp;nbsp;- In the top chart it's using the built in accumulation modifier, but it's a bit of a struggle to unpick and repurpose into the load script.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="ruby"&gt;Aggr(RangeSum(Above( (　sum(minutesUsed)　) , 0, RowNo())), ([$(=Replace(GetObjectField(1),']',']]'))], (Numeric, Ascending), (Text, Ascending)), ([$(=Replace(GetObjectField(0),']',']]'))], (Numeric, Ascending), (Text, Ascending)))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/336"&gt;@Kushal_Chawda&lt;/a&gt;&amp;nbsp; - I tried your code.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I'd have thought this was a simple thing&amp;nbsp; - it's trivial to do in SQL.&lt;BR /&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;Logic is-&amp;nbsp; accumulate CapcityUsed by date, and start over if CML_Month =CML_Date,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;The result should be a rolling sum that resets each month, per app&amp;nbsp; - as you can see it's a bit wonky.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="110_0-1730806968126.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/173811i22AD255BFE045DB6/image-size/large?v=v2&amp;amp;px=999" role="button" title="110_0-1730806968126.png" alt="110_0-1730806968126.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the latest code - I was getting peculiar repeated dates so had to floor the date field.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;[Cumulative]:

NoConcatenate

LOAD 
    appId,
    Date(Floor(MonthStart(Timestamp#(endTime, 'YYYY-MM-DDThh:mm:ss.fffZ')))) AS CMLMonth, // Rounds to the start of the month as date
    Date(Floor(Timestamp#(endTime, 'YYYY-MM-DDThh:mm:ss.fffZ'))) AS DateOnly, // Rounds to the date only (no time)
    capacityUsed AS TotalCapacityUsed

RESIDENT Entitlement_Consumption;


[MonthlyCumulative]:

NoConcatenate

LOAD
    appId,DateOnly as CMLDate,
    CMLMonth,
       // Get the month start for grouping by month
    /*If(CMLMonth = Peek('CMLMonth')AND appId = Peek('appId'),
        Peek('CumulativeCapacityUsed') + TotalCapacityUsed,TotalCapacityUsed) AS CumulativeCapacityUsed    // Calculate cumulative sum
*/
If(CMLMonth = Peek('CMLMonth')AND appId = Peek('appId'),
        rangesum(Peek('CumulativeCapacityUsed'),TotalCapacityUsed),TotalCapacityUsed) AS CumulativeCapacityUsed 

RESIDENT [Cumulative]
ORDER BY DateOnly,appId, CMLMonth;


Drop Table Cumulative;&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 05 Nov 2024 11:47:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490802#M102011</guid>
      <dc:creator>110</dc:creator>
      <dc:date>2024-11-05T11:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490804#M102012</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/180799"&gt;@110&lt;/a&gt;&amp;nbsp; it seems issue with Order by. I think order by should be like below&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;ORDER BY appId,CMLMonth,DateOnly;&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 05 Nov 2024 11:53:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490804#M102012</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2024-11-05T11:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490810#M102014</link>
      <description>&lt;P&gt;if possible share some sample data from table&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-ruby"&gt;&lt;CODE&gt;Entitlement_Consumption&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so i can recreate this scenario and look for any errors&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 12:01:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490810#M102014</guid>
      <dc:creator>Qrishna</dc:creator>
      <dc:date>2024-11-05T12:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490812#M102016</link>
      <description>&lt;P&gt;Thanks&amp;nbsp; &amp;nbsp;- I tried changing the ordering - maybe it's too complicated a thing to achieve in the load script?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Here in the chart, filtering on one month, final # should be 2,466&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="110_1-1730807935318.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/173812iB46A7EA27D1BE837/image-size/large?v=v2&amp;amp;px=999" role="button" title="110_1-1730807935318.png" alt="110_1-1730807935318.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Trying to do the same ( but with pre-calculated cumulative sum ) - it goes a bit wonky&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="110_2-1730808072180.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/173813i9D1699E152587FA8/image-size/large?v=v2&amp;amp;px=999" role="button" title="110_2-1730808072180.png" alt="110_2-1730808072180.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;It'd be great if there's some form of simplified syntax for loads on the roadmap that'd facilitate this , akin to how Excel has conditional range sum or average, or even how SQL does it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 12:03:07 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490812#M102016</guid>
      <dc:creator>110</dc:creator>
      <dc:date>2024-11-05T12:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490814#M102018</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/180799"&gt;@110&lt;/a&gt;&amp;nbsp; You could do it on front end. If you could share some sample dummy data with expected output, we can suggest required expression and even script approach&lt;/P&gt;</description>
      <pubDate>Tue, 05 Nov 2024 12:08:16 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2490814#M102018</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2024-11-05T12:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2491365#M102079</link>
      <description>&lt;P&gt;I've attached an example with some random data in the same format.&lt;/P&gt;
&lt;P&gt;So column D would be the desired output, where it performs a running sum in ascending date order, over the 'MonthYear' field, so the sum value resets per month.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="110_0-1730978449475.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/173968i81B72DB5787F50EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="110_0-1730978449475.png" alt="110_0-1730978449475.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;When charted , I'd expect to be able to produce the following visualization.&lt;/P&gt;
&lt;P&gt;I can do this with the modifiers in Qlik, however I'd like to do it specifically in the load script as a flat table, so I can highlight thresholds ( in this case , the data being minutes consumed )&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="example_chart_cumulative.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/173969iD5D6E6BC59290114/image-size/large?v=v2&amp;amp;px=999" role="button" title="example_chart_cumulative.png" alt="example_chart_cumulative.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Hopefully that makes sense?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 11:23:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2491365#M102079</guid>
      <dc:creator>110</dc:creator>
      <dc:date>2024-11-07T11:23:47Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2491371#M102080</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/180799"&gt;@110&lt;/a&gt;&amp;nbsp; try below expression. Assuming your Date &amp;amp; MonthYear are formatted as Numeric.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Replace&amp;nbsp;&lt;STRONG&gt;sum(CountDaily)&amp;nbsp;&lt;/STRONG&gt;with your actual count expression&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;=sum(aggr(rangesum(above(sum(CountDaily),0,RowNo())),(MonthYear,(NUMERIC)),(Date,(NUMERIC))))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Nov 2024 11:40:33 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2491371#M102080</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2024-11-07T11:40:33Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum in load script using Peek?</title>
      <link>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2494650#M102463</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/336"&gt;@Kushal_Chawda&lt;/a&gt;&amp;nbsp; &amp;nbsp;- that worked - I can now highlight where the running sum intersects the threshold.&amp;nbsp; Great stuff, and thanks again for your help!&lt;BR /&gt;&lt;BR /&gt;As below- conditional colouring where intersections hit:-&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="110_1-1732619803477.png" style="width: 999px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/174854iC47A465FBF0D6828/image-size/large?v=v2&amp;amp;px=999" role="button" title="110_1-1732619803477.png" alt="110_1-1732619803477.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Nov 2024 11:20:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Cumulative-Sum-in-load-script-using-Peek/m-p/2494650#M102463</guid>
      <dc:creator>110</dc:creator>
      <dc:date>2024-11-26T11:20:02Z</dc:date>
    </item>
  </channel>
</rss>

