Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
hi All,
I have below table
Product id | branch id | Ratio |
1 | 1 | 20 |
1 | 2 | 20 |
1 | 3 | 20 |
1 | 4 | 20 |
1 | 5 | 20 |
2 | 1 | 10 |
2 | 2 | 10 |
2 | 3 | 10 |
2 | 4 | 10 |
2 | 5 | 10 |
3 | 1 | 10 |
3 | 2 | 10 |
3 | 3 | 10 |
3 | 4 | 10 |
3 | 5 | 10 |
and i am trying to convert this into pivot via script and desired out should be
product id | branch_id_1 | branch_id_2 | branch_id_3 | branch_id_4 | branch_id_5 |
1 | 20 | 20 | 20 | 20 | 20 |
2 | 10 | 10 | 10 | 10 | 10 |
3 | 10 | 10 | 10 | 10 | 10 |
Kindly suggest
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;
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;