Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
AmCh
Creator
Creator

Generate Fields and Rows within a loop

Hi all,

simplified, there are here a while loop and statements:

set y=4;
let b=0;
let a=0;

do while a<y

let a=a+1

let b=b+a*2

loop

I want to generate this:

ab
13
27
313

 

Any help please?
Thanks in advance.

3 Replies
Or
MVP
MVP

Using a and b as both variable names and column names isn't the best idea, so I will refer to the variables as vA and vB here...

After setting the variables,

Load vA as a, vB as B

Autogenerate(1);

loop;

 

Frank_Hartmann
Master II
Master II

Maybe like this:

 

Set a=1;
Set b=1;
Set y=5;

Do while a<y

     Load $(a)-1 as a, $(b) as b AutoGenerate(1) Where $(a)-1<>0;
	 Let b=b+a*2;
     Let a=a+1;
Loop

 

AmCh
Creator
Creator
Author

Thank you for your reply. It works with that example. But as I tried to implement it to the concrete example; it showed an error message:

'Field names must be unique within table'

 

set v_max=34.72;

set delta=0.1
set s_k=3800;
set m=126000;
set delta_m=10000;
set factor_m=1.05;

do while v_a<$(v_max) and s_a<$(s_k)/2
LOAD $(t_a) as t_a,$(a1) as a1 AutoGenerate(1);
let b1=(F_a(v_a))/(m*$(factor_m)+$(delta_m));
let v_a=v_a+(a1+b1)*$(delta)/2;
let a1=b1;
let s_a=s_a+(c1+v_a)*$(delta)/2;
let c1=v_a;
let t_a=t_a+$(delta);
loop

 

I couldn't understand, where is the main difference here showing the error message.
Any help please?

Thanks in advance.