<?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: LOOP not working in Qlik Sense script in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654930#M48944</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/46628"&gt;@sunny_talwar&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for that, I have seen that you have included the Alt Function to avoid NULL values from Peek function, but although now Forecast variable do Exists, result for this variable has non sense to me.&lt;/P&gt;&lt;P&gt;Why?&lt;/P&gt;&lt;P&gt;Because the result is constant for all dates (0,35), whereas production values do not have the same values for all dates as you can see in the following table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Date,Action,Production
01/01/2019,Action1,100
01/01/2019,Action2,300
01/01/2019,Action23,550
02/01/2019,Action1,600
.......................
03/04/2019,Action23,1050
04/04/2019,Action1,1100&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Let try to explain what I am trying to see from variable V_result1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;for i = 1 to 7
	for j = 8 to 14
		for z = 15 to 21
     
            //// 2.These are variable FUNCTIONS with same structure
            LET V_result1 = Num(RangeSum(Alt(Peek('Result_1', $(i), 'DATE_PRODUCTION_3'), 0)*0.45, Alt(Peek('Result_1',$(j),'DATE_PRODUCTION_3'), 0)*0.35, Alt(Peek('Result_1',$(z),'DATE_PRODUCTION_3'))*0.2), '##0.000');
            &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the first part of formula&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Num(RangeSum(Alt(Peek('Result_1', $(i), 'DATE_PRODUCTION_3'), 0)*0.45&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am expecting a Range Sum of the latest 7 values of variable Result_1 for each date. Just to remmenber Result_1 variable multiplies Production Values (that are not equal for all date) by the same percentage and so has a unique value for each date.&lt;/P&gt;&lt;P&gt;Taking into account that is quite rare to me to see the variable Forecast with the same value for all dates, because it should be a value that change over time with variable result_1 that also changes simultanously&amp;nbsp; with&amp;nbsp; production values.&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;</description>
    <pubDate>Fri, 06 Dec 2019 10:33:35 GMT</pubDate>
    <dc:creator>luisccmm</dc:creator>
    <dc:date>2019-12-06T10:33:35Z</dc:date>
    <item>
      <title>LOOP not working in Qlik Sense script</title>
      <link>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654241#M48882</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am having a problem trying to do a FOR LOOP as it produces no values.&lt;/P&gt;&lt;P&gt;I am doing 3 steps, but not sure what is the problem, I have attached the APP.&lt;/P&gt;&lt;P&gt;1.Determin the FOR values of the variables above.&lt;/P&gt;&lt;P&gt;2.&amp;nbsp;Creating 2 variables&lt;/P&gt;&lt;P&gt;3. Apply the variables to TABLE from a RESIDENT table. But it produces no value after LOADING the script.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;/// 1. These are the FOR values to PASS for the variables below.

for i= -1 to -7 ;
 for j=-8 to -15;
 for z= -16 to -21
     
//// 2.These are variable FUNCTIONS with same structure
LET
     V_result1=(sum(Peek(Result_1,$i))*0.45+sum(Peek(Result_1,$j))*0.35+sum(Peek(Result_1,$z))*0.2)*1/5;
     V_result2=(sum(Peek(Result_2,$i))*0.45+sum(Peek(Result_2,$j))*0.35+sum(Peek(Result_2,$z))*0.2)*1/5;
 
 
//// 3. The table where to apply those VARIABLES from a RESIDENT table.
DATE_PRODUCTION_4;
LOAD 
    "Date",
    Sum($(V_result1)) as Forecast1,
    sum($(V_result2)) as Forecast2
 
Resident [DATE_PRODUCTION_3]
GROUP BY "Date";&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 16 Nov 2024 03:55:28 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654241#M48882</guid>
      <dc:creator>luisccmm</dc:creator>
      <dc:date>2024-11-16T03:55:28Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP not working in Qlik Sense script</title>
      <link>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654253#M48884</link>
      <description>&lt;P&gt;May be this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;/// 1. These are the FOR values to PASS for the variables below.
for i= -1 to -7
	for j=-8 to -15
		for z= -16 to -21
     
            //// 2.These are variable FUNCTIONS with same structure
            LET V_result1=((Peek(Result_1,$(i)))*0.45+(Peek(Result_1,$(j))*0.35+(Peek(Result_1,$(z)))*0.2)*1/5;
            LET V_result2=((Peek(Result_2,$(i)))*0.45+(Peek(Result_2,$(j)))*0.35+sum(Peek(Result_2,$(z)))*0.2)*1/5;


            //// 3. The table where to apply those VARIABLES from a RESIDENT table.
            DATE_PRODUCTION_4:
            LOAD  "Date",
                Sum($(V_result1)) as Forecast1,
                sum($(V_result2)) as Forecast2
            Resident [DATE_PRODUCTION_3]
            GROUP BY "Date";


            DATE_PRODUCTION_5:
            CrossTable ("Accion Marketing",Forecast,1)
            LOAD
                Date,
                Forecast1,
                Forecast2

            RESIDENT DATE_PRODUCTION_4;
            DROP TABLE DATE_PRODUCTION_4;

		NEXT;
	NEXT;
NEXT;&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 04 Dec 2019 17:56:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654253#M48884</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-12-04T17:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP not working in Qlik Sense script</title>
      <link>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654439#M48900</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/46628"&gt;@sunny_talwar&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I have tested but still produce the same result.&lt;/P&gt;&lt;P&gt;Variable FORECAST does not exists.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot_2.jpg" style="width: 247px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/24964i14AEAC73B3FB02E4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot_2.jpg" alt="Screenshot_2.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I have TEST the Following:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1) Creat a 3rd variable called Forecast 3 that is not produced froma CALL to variable produce by a LET FOR STATEMENTS.&lt;/P&gt;&lt;P&gt;2) Removing the later step with the crosstable function.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RESULT&lt;/STRONG&gt;: Forecast1, Forecast2 and Forecast3 &lt;U&gt;&lt;STRONG&gt;does not exists&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Don´t know what I am doing wrong?&lt;/STRONG&gt;&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; DATE_PRODUCTION_4:
            LOAD  "Date",
                Sum($(V_result1)) as Forecast1,
                sum($(V_result2)) as Forecast2,
                Peek(Result_2,1)+Peek(Result_2,2) as Forecast3
            Resident [DATE_PRODUCTION_3]
            GROUP BY "Date";&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 09:54:49 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654439#M48900</guid>
      <dc:creator>luisccmm</dc:creator>
      <dc:date>2019-12-05T09:54:49Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP not working in Qlik Sense script</title>
      <link>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654493#M48905</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;couple of observations&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. i think a for loop in qlik always adds 1 in the end off the loop&amp;nbsp;&lt;/P&gt;&lt;P&gt;so you'll need to go from the lower number to the bigger&amp;nbsp;&lt;/P&gt;&lt;P&gt;i did some modifications to your script&lt;/P&gt;&lt;P&gt;&amp;nbsp;and variables ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;another thing if you try to reference a row that isn't exists you'll get a null&amp;nbsp;&lt;/P&gt;&lt;P&gt;so increase your rows in your demos&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 10:17:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654493#M48905</guid>
      <dc:creator>lironbaram</dc:creator>
      <dc:date>2019-12-05T10:17:32Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP not working in Qlik Sense script</title>
      <link>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654575#M48917</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/6330"&gt;@lironbaram&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your proposal,&amp;nbsp; seems quite good, BUT after modifiying the script to increase the dates of Production as you sugested, Forecast values are NULL.&amp;nbsp; Altough at least Forecast variable do exists.&lt;/P&gt;&lt;P&gt;I have attached the app again, this what I have change:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;¿WHAT I have Done?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1) Change production time dates&lt;/STRONG&gt;, and spot some of them a few month later.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Date,Action,Production
01/01/2019,Action1,100
01/01/2019,Action2,300
01/01/2019,Action23,550
02/01/2019,Action1,600
02/02/2019,Action2,650
02/02/2019,Action3,700
02/02/2019,Action31,750
02/03/2019,Action23,800
03/03/2019,Action1,850
03/03/2019,Action2,900
03/04/2019,Action3,950
03/04/2019,Action31,1000
03/04/2019,Action23,1050
04/04/2019,Action1,1100&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2) Change FOR values&lt;/STRONG&gt; as follows&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;for i= -7 to -1
	for j=-14 to -7
		for z= -21 to -15&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;3) Incluide RangeSum function&lt;/STRONG&gt; in front each Peek function as follow.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;LET V_result1=num(((Rangesum(Peek('Result_1',$(i),'DATE_PRODUCTION_3')))*0.45+(Rangesum(Peek('Result_1',$(j),'DATE_PRODUCTION_3')))*0.35+(Rangesum(Peek('Result_1',$(z),'DATE_PRODUCTION_3')))*0.2)*1/5,'##0.000')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RESULT on FORECAST variable&lt;/STRONG&gt;:&lt;/P&gt;&lt;P&gt;-Forecast variable do Exists.&lt;/P&gt;&lt;P&gt;-But &lt;STRONG&gt;produce NULL&lt;/STRONG&gt; values always.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 13:24:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654575#M48917</guid>
      <dc:creator>luisccmm</dc:creator>
      <dc:date>2019-12-05T13:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP not working in Qlik Sense script</title>
      <link>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654730#M48932</link>
      <description>&lt;P&gt;Can you check if the attached works for you&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 18:09:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654730#M48932</guid>
      <dc:creator>sunny_talwar</dc:creator>
      <dc:date>2019-12-05T18:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP not working in Qlik Sense script</title>
      <link>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654930#M48944</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/46628"&gt;@sunny_talwar&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Thanks for that, I have seen that you have included the Alt Function to avoid NULL values from Peek function, but although now Forecast variable do Exists, result for this variable has non sense to me.&lt;/P&gt;&lt;P&gt;Why?&lt;/P&gt;&lt;P&gt;Because the result is constant for all dates (0,35), whereas production values do not have the same values for all dates as you can see in the following table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Date,Action,Production
01/01/2019,Action1,100
01/01/2019,Action2,300
01/01/2019,Action23,550
02/01/2019,Action1,600
.......................
03/04/2019,Action23,1050
04/04/2019,Action1,1100&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Let try to explain what I am trying to see from variable V_result1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;for i = 1 to 7
	for j = 8 to 14
		for z = 15 to 21
     
            //// 2.These are variable FUNCTIONS with same structure
            LET V_result1 = Num(RangeSum(Alt(Peek('Result_1', $(i), 'DATE_PRODUCTION_3'), 0)*0.45, Alt(Peek('Result_1',$(j),'DATE_PRODUCTION_3'), 0)*0.35, Alt(Peek('Result_1',$(z),'DATE_PRODUCTION_3'))*0.2), '##0.000');
            &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the first part of formula&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Num(RangeSum(Alt(Peek('Result_1', $(i), 'DATE_PRODUCTION_3'), 0)*0.45&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am expecting a Range Sum of the latest 7 values of variable Result_1 for each date. Just to remmenber Result_1 variable multiplies Production Values (that are not equal for all date) by the same percentage and so has a unique value for each date.&lt;/P&gt;&lt;P&gt;Taking into account that is quite rare to me to see the variable Forecast with the same value for all dates, because it should be a value that change over time with variable result_1 that also changes simultanously&amp;nbsp; with&amp;nbsp; production values.&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;</description>
      <pubDate>Fri, 06 Dec 2019 10:33:35 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1654930#M48944</guid>
      <dc:creator>luisccmm</dc:creator>
      <dc:date>2019-12-06T10:33:35Z</dc:date>
    </item>
    <item>
      <title>Re: LOOP not working in Qlik Sense script</title>
      <link>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1655107#M48953</link>
      <description>&lt;P&gt;I... don't think for loops work like that.&lt;/P&gt;&lt;P&gt;I might be completely off base here, but you seem to be trying to do some kind of moving window calculation, so for each date sum up the previous week and multiply by some weight, the week before previous and multiply by some other weight, and finally the week two weeks before previous and multiply by yet another weight. Finally multiply the total result by yet another factor (1/5). This is done separately for each action, which is why you have multiple result columns.&lt;/P&gt;&lt;P&gt;So assuming you have one row per date, you would want to sum up a total of 21 rows for each date (3*7). With three nested for loops, you'd make a total of 7^3 = 343 iterations for each date. Even if you &lt;EM&gt;could&lt;/EM&gt; use for loop as some kind of generator for the variable formula, which you can't because Qlik script does not do generators.&lt;/P&gt;&lt;P&gt;If my idea of what you are trying to do is correct, I would do it completely differently:&lt;/P&gt;&lt;P&gt;1. Create a date bridge table from master calendar. So, for each date generate "linking dates" going back 3 weeks, using while clause. Additionally create a "week difference" field which would range from 1 to 3&lt;BR /&gt;2. Left join your facts (DATE_PRODUCTION_3) to that, using linking dates as key&lt;BR /&gt;3. Group the resulting table by date (the original one, not the linking one), with something like Sum(Result * (pick("week difference"), 0.45, 0.35, 0.2)) as the aggregation formula&lt;BR /&gt;4. Finally do a resident load from that and multiply each aggregation result by 1/5&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2019 17:27:55 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/LOOP-not-working-in-Qlik-Sense-script/m-p/1655107#M48953</guid>
      <dc:creator>kuba_michalik</dc:creator>
      <dc:date>2019-12-06T17:27:55Z</dc:date>
    </item>
  </channel>
</rss>

