Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Whateverest
Contributor
Contributor

looping over inline table loads distinct data

Hello All,

while looping over an inline table I experienced something that i do not understand. The following script creates the output shown as "Reality Output", but i would expect the output to be like "Expected Output". Can someone explain give advice how i can load the data so i get the desired output?

 

[Table]:

Load * inline

[

Column1, Column2

Test,Value 1

Test,Value 2

Test1, Value 3

];

 

LET NumRows=NoOfRows('Table');

 

FOR i=1 to $(NumRows)

 

  LET vColumn1=FieldValue('Column1',$(i));

  LET vColumn2=FieldValue('Column2',$(i));

 

  Trace 'DEBUG: ' $(vColumn1) ',' $(vColumn2);

 

NEXT;

 

/*Expection Output:

'DEBUG: ' Test ',' Value 1

'DEBUG: ' Test ',' Value 2

'DEBUG: ' Test 1 ',' Value 3

 

Reality Output:

'DEBUG: ' Test ',' Value 1

'DEBUG: ' Test1 ',' Value 2

'DEBUG: '  ',' Value 3

 

*/

1 Solution

Accepted Solutions
tresesco
MVP
MVP

Try like:

 

LET NumRows=NoOfRows('Table');

FOR i=0 to $(NumRows)-1

LET vColumn1=Peek('Column1',$(i));
LET vColumn2=Peek('Column2',$(i));

Trace 'DEBUG: ' $(vColumn1) ',' $(vColumn2);


NEXT;

View solution in original post

3 Replies
tresesco
MVP
MVP

FieldValue() doesn't work on record count, but on distinct count of field values. In your field Column1, there are two values and they would be indexed as :

Field                Value    Index

Column1        Test        1

Column1        Test        1

Column1        Test1      2

 

Now you can interpret, I guess.

Whateverest
Contributor
Contributor
Author

thank you for the reply - i understand. Is there any other way to get the data out of the inline table in the way that i need it to?

tresesco
MVP
MVP

Try like:

 

LET NumRows=NoOfRows('Table');

FOR i=0 to $(NumRows)-1

LET vColumn1=Peek('Column1',$(i));
LET vColumn2=Peek('Column2',$(i));

Trace 'DEBUG: ' $(vColumn1) ',' $(vColumn2);


NEXT;