Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
luisccmm
Creator
Creator

FOR LOOP in script not working

Hi,

I am having a problem trying to do a FOR LOOP as it produces no values.

I am doing 3 steps, but not sure what is the problem, I have attached the APP.

1. Creating 2 variables ( 2 in this test, but in fact are more)

2. Determin the FOR values of the variables above.

3. Apply the variables to TABLE from a RESIDENT table. But it produces no value after LOADING the script.

 

/// 1. These are variable FUNCTIONS with same structure
LET
     V_result1=(sum(Peek(Result_1,$i))*0.45+sum(Peek(Result_1,$j))*0.35)*1/5;
     V_result2=(sum(Peek(Result_2,$i))*0.45+sum(Peek(Result_2,$j))*0.35)*1/5;
//// 2. These are the FOR values to PASS for the variables above.
 for i= -1 to -7 ;
 for j=-8 to -15;
//// 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";

 

 

 

 

Labels (3)
1 Reply
lfetensini
Partner - Creator II
Partner - Creator II


It's hard to try to answer you with this example, but lets go.


The first point is that the FOR is always i+1. If you want i-1 then you need to add "step -1" to the function. Example:

For i = -1 to -7 step -1

 

It also seems to me that you want to create a loop inside another, in case you need to respect this condition and have the Next functions to sequence it.

For i = -1 to -7 step -1

For j = -8 to -15 step -1

LET V_result1 = (sum(Peek(Result_1,$i))*0.45+sum(Peek(Result_1,$j))*0.35)*1/5;
LET V_result2 = (sum(Peek(Result_2,$i))*0.45+sum(Peek(Result_2,$j))*0.35)*1/5;

// Script HERE

Next // For j

Next // For i

Support your colleagues. Remember to "like" the answers that are helpful to you and flag as "solved" the one that helped you solve. Cheers.