Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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?
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
....;
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