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

Loop in a script

Hi all,

i would need your help on this topic:

I am getting following Data under Qlikview:

JR_38_0-1714144495534.png

I would like to assign the field-information from "AREA-EAN" when the Datatyp='AREA'  as own column for the following eans, and then remove the line related to the datatyp "AREA" .

It should look like this:

JR_38_1-1714145212860.png

I set different variables in order to use it in my first loop but the for...next doens´t work.

INV_RAWDATA:
 
LOAD * INLINE [
ID, Datatyp, AREA_EAN, Qty
1, AREA, A-30-D-00, 1
2, EANS, 4062171924956, 2
3, EANS, 4062171874947, 2
4, EANS, 4062171912946, 1
5, EANS, 4062171924956, 1
6, EANS, 4062171924956, 1
7, AREA, A-29-D-00, 1
8, EANS, 4062171874930, 1
9, EANS, 4062171912946, 1
10, EANS, 4066952504313, 1
11, EANS, 4066952504320, 1
12, EANS, 4066952504320, 1
13, EANS, 4066952504320, 1
];
 
Store INV_RAWDATA into File.qvd;
 
// set Variable with information
VARIABLE_I:
 
set i=1;
 
LOAD ID, 
     AREA_EAN, 
     Datatyp, 
     Qty
FROM File.qvd (qvd) where ID=$(i) and Datatyp='AREA';
 
let i=$(i)+1;
let AREA=peek('AREA_EAN',0,'VARIABLE_I');
 
VARIABLE_II:
LOAD 
max(ID) as max_i    
FROM
File.qvd (qvd);
let max_i=peek('max_i',0,'VARIABLE_II');
 
 
// 
 
FOR i=$(i) to max_i=$(max_i)
 
RUN:
 
LOAD 
'$(AREA)' as AREA,
ID, 
     AREA_EAN, 
     Datatyp, 
     Qry
FROM
File.qvd (qvd) ; 
 
NEXT

 

Has somebody any idea how I could get the desired result?

Labels (1)
1 Solution

Accepted Solutions
rubenmarin

Hello, this script gets the result table:

OrigData:
LOAD * INLINE [
ID, Datatyp, AREA_EAN, Qty
1, AREA, A-30-D-00, 1
2, EANS, 4062171924956, 2
3, EANS, 4062171874947, 2
4, EANS, 4062171912946, 1
5, EANS, 4062171924956, 1
6, EANS, 4062171924956, 1
7, AREA, A-29-D-00, 1
8, EANS, 4062171874930, 1
9, EANS, 4062171912946, 1
10, EANS, 4066952504313, 1
11, EANS, 4066952504320, 1
12, EANS, 4066952504320, 1
13, EANS, 4066952504320, 1
];
 
ProcessData:
NoConcatenate LOAD
	ID,
	Datatyp,
	If(Datatyp='EANS', Peek(AREA_EAN), AREA_EAN) as AREA_EAN,
	Qty
Resident OrigData;

DROP Table OrigData;

FinalData:
NoConcatenate LOAD * Resident ProcessData where Datatyp='EANS';

DROP Table ProcessData;

View solution in original post

2 Replies
rubenmarin

Hello, this script gets the result table:

OrigData:
LOAD * INLINE [
ID, Datatyp, AREA_EAN, Qty
1, AREA, A-30-D-00, 1
2, EANS, 4062171924956, 2
3, EANS, 4062171874947, 2
4, EANS, 4062171912946, 1
5, EANS, 4062171924956, 1
6, EANS, 4062171924956, 1
7, AREA, A-29-D-00, 1
8, EANS, 4062171874930, 1
9, EANS, 4062171912946, 1
10, EANS, 4066952504313, 1
11, EANS, 4066952504320, 1
12, EANS, 4066952504320, 1
13, EANS, 4066952504320, 1
];
 
ProcessData:
NoConcatenate LOAD
	ID,
	Datatyp,
	If(Datatyp='EANS', Peek(AREA_EAN), AREA_EAN) as AREA_EAN,
	Qty
Resident OrigData;

DROP Table OrigData;

FinalData:
NoConcatenate LOAD * Resident ProcessData where Datatyp='EANS';

DROP Table ProcessData;
JR_38
Contributor
Contributor
Author

exactly what I wanted and so an easy way to solve the problem, thanks