Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
anonymous1
Contributor III
Contributor III

for loop error

hello,

im trying to create a loop that will iterate over all item_id's that end in 'A':


for (RIGHT(ITEM_ID, 1) = 'A')

NEXT

can anyone tell me why this is wrong?

Labels (2)
2 Replies
petter
Partner - Champion III
Partner - Champion III

The FOR syntax does not allow a use like that - you will have to study the documentation and examples to see how FOR can be used.

For your specific case you might do this:

FOR v IN FieldValueList('ITEM_ID')
  IF Right(v,1)='A' THEN
      .......
  END IF
NEXT

The FOR can't be used while you load a table within a LOAD statement though... So without the wider context of how you intend to use it my suggestion might be useless.

FieldValueList() function will only give all the unique values in the field ITEM_ID and not row-wise like it is in the table(s) where the field is located.

This iterates through all the rows of the containing table where ITEM_ID is:

FOR row=1 TO NoOfRows('TABLE_WHERE_ITEM_ID_IS')
   IF Peek('ITEM_ID',row-1,'TABLE_WHERE_ITEM_ID_IS') THEN
      ....
   END IF
NEXT

 

Maybe this is what you need to do instead:

LOAD
    If( Right(ITEM_ID,1)=A, <true-expression> , <false-expression> ) AS ResultingField,
    .....
FROM
   ....;

 

Brett_Bleess
Former Employee
Former Employee

Natasha, did Petter's reply help you get things sorted?  If so, be sure to give credit by clicking the Accept as Solution.  If you did something else, please post that and mark that as the solution, so others can learn from it too.

I have one thing from the Design Blog, related to Petter's comment that may help, hopefully.

https://community.qlik.com/t5/Qlik-Design-Blog/Loops-in-the-Script/ba-p/1473543

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.