Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
manideep78
Partner - Specialist
Partner - Specialist

CONCAT function with Sort weight

Dear Community,

I have an input like table 1 and expecting output like table2.

I would like to use Concat function without distinct but my priority is sort order. My sort order is based on Col1 and Col2 and ignore the default concat sort.

either script function or chart function is fine, but recommend in script because I have to display my output in table box.

Table-1: Input

Col1Col2Col3Col4Col5
1AAA3PQR
1BBB1ABC
1CCC2XYZ
2XXX100XXX
2YYY101YYY
3PPP200PPP
3PPP350PPP
3QQQ250QQQ
3RRR300RRR

 

Table -2: Output

Col1Col2Col3Col4Col5
1A,B,CAA,BB,CC3,1,2PQR,ABC,XYZ
2X,YXX,YY100,101XXX,YYY
3P,P,Q,RPP,PP,QQ,RR200,350,250,300PPP,PPP,QQQ,RRR

 

Thanks in advance!

 

1 Solution

Accepted Solutions
Taoufiq_Zarra

@manideep78  or this :

Input:

LOAD *,rowno() as Numtmp INLINE [
    Col1, Col2, Col3, Col4, Col5
    1, A, AA, 3, PQR
    1, B, BB, 1, ABC
    1, C, CC, 2, XYZ
    2, X, XX, 100, XXX
    2, Y, YY, 101, YYY
    3, P, PP, 200, PPP
    3, P, PP, 350, PPP
    3, Q, QQ, 250, QQQ
    3, R, RR, 300, RRR
];

output:
noconcatenate


load Col1,concat(Col2,',',Numtmp) as Col2,concat(Col3,',',Numtmp) as Col3,concat(Col4,',',Numtmp) as Col4,concat(Col5,',',Numtmp) as Col5 resident Input group by Col1;

drop table Input;

output:

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

5 Replies
Anil_Babu_Samineni

PFA, IF this is what you expecting?

Concat.png

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Taoufiq_Zarra

@manideep78  May be this version :

Input:

LOAD * INLINE [
    Col1, Col2, Col3, Col4, Col5
    1, A, AA, 3, PQR
    1, B, BB, 1, ABC
    1, C, CC, 2, XYZ
    2, X, XX, 100, XXX
    2, Y, YY, 101, YYY
    3, P, PP, 200, PPP
    3, P, PP, 350, PPP
    3, Q, QQ, 250, QQQ
    3, R, RR, 300, RRR
];

output:
noconcatenate


load Col1,concat(Col2,',',recno()) as Col2,concat(Col3,',',recno()) as Col3,concat(Col4,',',recno()) as Col4,concat(Col5,',',recno()) as Col5 resident Input group by Col1;

drop table Input;

 

output :

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
Taoufiq_Zarra

@manideep78  or this :

Input:

LOAD *,rowno() as Numtmp INLINE [
    Col1, Col2, Col3, Col4, Col5
    1, A, AA, 3, PQR
    1, B, BB, 1, ABC
    1, C, CC, 2, XYZ
    2, X, XX, 100, XXX
    2, Y, YY, 101, YYY
    3, P, PP, 200, PPP
    3, P, PP, 350, PPP
    3, Q, QQ, 250, QQQ
    3, R, RR, 300, RRR
];

output:
noconcatenate


load Col1,concat(Col2,',',Numtmp) as Col2,concat(Col3,',',Numtmp) as Col3,concat(Col4,',',Numtmp) as Col4,concat(Col5,',',Numtmp) as Col5 resident Input group by Col1;

drop table Input;

output:

Capture.PNG

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
manideep78
Partner - Specialist
Partner - Specialist
Author

This has the sort issue in col4, row 3.

it should be

200,350,250,300
manideep78
Partner - Specialist
Partner - Specialist
Author

I had to tweak little bit because I cannot drop the table as I have more than 100 columns and cannot mention all of them in group by.

I just took the key and the columns that need to be concatenated in a separate table using resident load and then applied the similar logic what you said. so, I can accept this as correct solution.