Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
New-Qlik
Creator II
Creator II

pivot table in script

hi All,

 

I have below table 

Product idbranch idRatio
1120
1220
1320
1420
1520
2110
2210
2310
2410
2510
3110
3210
3310
3410
3510

 

 

and i am trying to convert this into pivot via script and desired out should be 

product id branch_id_1branch_id_2branch_id_3branch_id_4branch_id_5
12020202020
21010101010
31010101010

 

 

Kindly suggest

1 Solution

Accepted Solutions
StarinieriG
Partner - Specialist
Partner - Specialist

Hi 

you could try like this

 

BRANCH_ID:
LOAD Distinct [branch id] as branch_id
FROM
TABLE.QVD
(qvd);

NoConcatenate
TABLE:
LOAD
[Product id]
FROM
TABLE.QVD
(qvd);

FOR i=0 to NoOfRows('BRANCH_ID')-1

LET Branch_id = Peek('branch_id',$(i),'BRANCH_ID');

Join (TABLE)
LOAD
[Product id],
Ratio AS branch_id_$(Branch_id)
FROM
TABLE.QVD
(qvd)
Where [branch id]='$(Branch_id)'
;
NEXT

DROP Table BRANCH_ID;

View solution in original post

1 Reply
StarinieriG
Partner - Specialist
Partner - Specialist

Hi 

you could try like this

 

BRANCH_ID:
LOAD Distinct [branch id] as branch_id
FROM
TABLE.QVD
(qvd);

NoConcatenate
TABLE:
LOAD
[Product id]
FROM
TABLE.QVD
(qvd);

FOR i=0 to NoOfRows('BRANCH_ID')-1

LET Branch_id = Peek('branch_id',$(i),'BRANCH_ID');

Join (TABLE)
LOAD
[Product id],
Ratio AS branch_id_$(Branch_id)
FROM
TABLE.QVD
(qvd)
Where [branch id]='$(Branch_id)'
;
NEXT

DROP Table BRANCH_ID;