<?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 by Year and Product in Script (QlikView) in Water Cooler</title>
    <link>https://community.qlik.com/t5/Water-Cooler/Cumulative-Sum-by-Year-and-Product-in-Script-QlikView/m-p/1915163#M12886</link>
    <description>&lt;P&gt;There is no else-branch within the if-loop. You may it trying in this way:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;load *, -(RELN_iCNR_CUMULATIVE_YR &amp;gt;= 1000) as RevenueFlag;&lt;/STRONG&gt;&lt;BR /&gt;load *,&lt;BR /&gt;IF(Previous(CLIENT) = CLIENT AND &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Previous(FACT_YEAR) = FACT_YEAR AND &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Previous(PRODUCT) = PRODUCT,&lt;BR /&gt;RangeSum(peek('RELN_iCNR_CUMULATIVE_YR'), AMOUNT),&lt;BR /&gt;&lt;STRONG&gt;AMOUNT&lt;/STRONG&gt;) AS RELN_iCNR_CUMULATIVE_YR&lt;BR /&gt;resident Source&lt;BR /&gt;order by CLIENT, FACT_YEAR, PRODUCT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 06 Apr 2022 12:32:48 GMT</pubDate>
    <dc:creator>marcus_sommer</dc:creator>
    <dc:date>2022-04-06T12:32:48Z</dc:date>
    <item>
      <title>Cumulative Sum by Year and Product in Script (QlikView)</title>
      <link>https://community.qlik.com/t5/Water-Cooler/Cumulative-Sum-by-Year-and-Product-in-Script-QlikView/m-p/1914985#M12884</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to solve a problem in my load script of doing a cumulative sum but where I have multiple years and 3 products over which I want to sum.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My objective is to have a cumulative sum specific to a year and a product so I can compare the year by year cumulative figure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been able to setup a cumulative sum in the script using this code:&amp;nbsp;&lt;/P&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;
&lt;LI-CODE lang="markup"&gt;IF(Previous(CLIENT) = CLIENT,RangeSum(peek('RELN_iCNR_CUMULATIVE'), AMOUNT)) AS RELN_iCNR_CUMULATIVE​&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;
&lt;P&gt;This works to calculate cumulative across the whole time period.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I want to make this work within dimensions I tried this:&amp;nbsp;&lt;/P&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;
&lt;LI-CODE lang="markup"&gt;IF(Previous(CLIENT) = CLIENTAND Previous(FACT_YEAR) = FACT_YEAR AND Previous(PRODUCT) = PRODUCT,RangeSum(peek('RELN_iCNR_CUMULATIVE_YR'), AMOUNT)) AS RELN_iCNR_CUMULATIVE_YR&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which will work but gives a blank for the first month in a year.&lt;/P&gt;
&lt;P&gt;My end point objective is to count where this cumulative sum &amp;gt; 1000 and compare this year by year. For instance if a client makes 500 revenue in Jan, count = 0, 500 in Feb, count = 1 (500+500) and continues as 1 for the rest of the year&lt;/P&gt;
&lt;P&gt;Really appreciate any pointers. I may be over complicating this&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 11:57:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Water-Cooler/Cumulative-Sum-by-Year-and-Product-in-Script-QlikView/m-p/1914985#M12884</guid>
      <dc:creator>ben2r</dc:creator>
      <dc:date>2022-04-06T11:57:22Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by Year and Product in Script (QlikView)</title>
      <link>https://community.qlik.com/t5/Water-Cooler/Cumulative-Sum-by-Year-and-Product-in-Script-QlikView/m-p/1915163#M12886</link>
      <description>&lt;P&gt;There is no else-branch within the if-loop. You may it trying in this way:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;load *, -(RELN_iCNR_CUMULATIVE_YR &amp;gt;= 1000) as RevenueFlag;&lt;/STRONG&gt;&lt;BR /&gt;load *,&lt;BR /&gt;IF(Previous(CLIENT) = CLIENT AND &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Previous(FACT_YEAR) = FACT_YEAR AND &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;Previous(PRODUCT) = PRODUCT,&lt;BR /&gt;RangeSum(peek('RELN_iCNR_CUMULATIVE_YR'), AMOUNT),&lt;BR /&gt;&lt;STRONG&gt;AMOUNT&lt;/STRONG&gt;) AS RELN_iCNR_CUMULATIVE_YR&lt;BR /&gt;resident Source&lt;BR /&gt;order by CLIENT, FACT_YEAR, PRODUCT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 12:32:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Water-Cooler/Cumulative-Sum-by-Year-and-Product-in-Script-QlikView/m-p/1915163#M12886</guid>
      <dc:creator>marcus_sommer</dc:creator>
      <dc:date>2022-04-06T12:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by Year and Product in Script (QlikView)</title>
      <link>https://community.qlik.com/t5/Water-Cooler/Cumulative-Sum-by-Year-and-Product-in-Script-QlikView/m-p/1915193#M12887</link>
      <description>&lt;P&gt;In case anyone is here looking for the same, I managed to solve the issue from 2 logic steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) The reason the cumulative sum was not working was initially to do with the order in which I sort the table to do the cumulative calculation. Once I looked at the raw data table and worked out the sequence it became clear. Quick tip here is to do a cumulative sum excluding the extra dimension (i.e. year in this case) and then sort the raw table by this value. That will show you how it is being sorted in practice.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Once 1) was solved I still had the issue of gaps for the first year in each section. Using the insight from here:&amp;nbsp;&lt;A href="https://community.qlik.com/t5/QlikView-App-Dev/Script-cumulative-sum-group-by/td-p/1810410" target="_blank"&gt;https://community.qlik.com/t5/QlikView-App-Dev/Script-cumulative-sum-group-by/td-p/1810410&lt;/A&gt;&amp;nbsp;I was able to see a solution of adding an initial logic to say 'if current year is not the same as previous then return the value, else perform the cumulative sum' Resulting code below:&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;IF(FIN_FACT_YEAR &amp;lt;&amp;gt; Previous(FIN_FACT_YEAR),FIN_PROD_MONTHLY_iCNR,
		IF(FIN_CLIENT_NBR = Previous(FIN_CLIENT_NBR) AND FIN_FACT_YEAR=Previous(FIN_FACT_YEAR),RangeSum(peek('RELN_iCNR_CUMULATIVE_LOGIC'), FIN_PROD_MONTHLY_iCNR))) AS RELN_iCNR_CUMULATIVE_LOGIC&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 06 Apr 2022 13:02:37 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Water-Cooler/Cumulative-Sum-by-Year-and-Product-in-Script-QlikView/m-p/1915193#M12887</guid>
      <dc:creator>ben2r</dc:creator>
      <dc:date>2022-04-06T13:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Cumulative Sum by Year and Product in Script (QlikView)</title>
      <link>https://community.qlik.com/t5/Water-Cooler/Cumulative-Sum-by-Year-and-Product-in-Script-QlikView/m-p/1915197#M12888</link>
      <description>&lt;P&gt;Thanks Marcus - I like the flag option here I had not thought of that. I was going to do the calculation in the dashboard for this part but the flag may be cleaner and faster no doubt&lt;/P&gt;</description>
      <pubDate>Wed, 06 Apr 2022 13:05:06 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Water-Cooler/Cumulative-Sum-by-Year-and-Product-in-Script-QlikView/m-p/1915197#M12888</guid>
      <dc:creator>ben2r</dc:creator>
      <dc:date>2022-04-06T13:05:06Z</dc:date>
    </item>
  </channel>
</rss>

