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

For each loop implementation

Hi Everyone,

Can anyone please provide me help in the 'for each loop' implementation. Here I'm attaching a qvw file.

Requirement is as below

as in below Image I want to put qty 5  through 'for each loop', on marked place, means when according to one itemid the location is change then qty should be 5.

I'm not able to implement for each loop in this please anyone provide some idea.

Thanks

Capture1.PNG.png

7 Replies
anbu1984
Master III
Master III

Temp:

LOAD * INLINE [

    ItemID, LocationID, Date, Qty

    I1, L1, 01-05-14, 5

    I1, L1, 02-05-14,

    I1, L1, 03-05-14,

    I1, L2, 04-05-14,

    I1, L2, 05-05-14,

    I2, L2, 06-05-14,

    I2, L3, 07-05-14,

    I3, L3, 08-05-14,

    I3, L3, 09-05-14,

    I3, L4, 10-05-14,

    I3, L1, 11-05-14,

    I4, L4, 12-05-14,

    I4, L3, 13-05-14,

    I4, L4, 14-05-14,

    I4, L5, 15-05-14,

    I5, L2, 16-05-14,

    I5, L5, 17-05-14,

    I5, L5, 18-05-14,

    I5, L1, 19-05-14,

];

NoConcatenate

tmp:

Load ItemID, LocationID, Date, If( ItemID & LocationID <> Previous(ItemID) & Previous(LocationID),FieldValue('Qty',1)) As Qty

Resident Temp

ORDER BY ItemID, LocationID;


DROP Table Temp;

jagan
Luminary Alumni
Luminary Alumni

Hi,

Try this script

Temp:

LOAD * INLINE [

    ItemID, LocationID, Date, Qty

    I1, L1, 01-05-14, 5

    I1, L1, 02-05-14,

    I1, L1, 03-05-14,

    I1, L2, 04-05-14,

    I1, L2, 05-05-14,

    I2, L2, 06-05-14,

    I2, L3, 07-05-14,

    I3, L3, 08-05-14,

    I3, L3, 09-05-14,

    I3, L4, 10-05-14,

    I3, L1, 11-05-14,

    I4, L4, 12-05-14,

    I4, L3, 13-05-14,

    I4, L4, 14-05-14,

    I4, L5, 15-05-14,

    I5, L2, 16-05-14,

    I5, L5, 17-05-14,

    I5, L5, 18-05-14,

    I5, L1, 19-05-14,

];

Data:

LOAD

*,

If(Previous(ItemID) <> ItemID OR LocationID <> Previous(LocationID),5) AS NewQty;

LOAD

*

RESIDENT Temp

ORDER BY ItemID, LocationID;

DROP TABLE Temp;

Regards,

Jagan.

Not applicable
Author

Hi anbu,

Thanks for the reply . This logic is working but I want to implement for each loop in the script.

jagan
Luminary Alumni
Luminary Alumni

Hi Manoj,

For loop will have performance issues, if you are able to do it without loop then try without using loops.  Using loops is not suggestible.

Regards,

Jagan.

Not applicable
Author

Hi jagan,

Thank you so much for the reply and suggestions. This logic is working fine .

Actually I am learning that how to use for each loop in qlikview script.

Thanks

jagan
Luminary Alumni
Luminary Alumni

jagan
Luminary Alumni
Luminary Alumni

Hi,

Check this link for Do While example

Connect to Database until success

Regards,

Jagan.