Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
basav
Creator
Creator

Split comma separated values in column into rows and How to Rank Each customer Record Separately in Load Script

Hi All,

I want to Split comma separated values in a column into rows, and then rank each Items row of Individual customer separately, please find my test script below:

 

Source_Data:

Load * Inline [

Group_Id,Items

Customer1,"Bread,Biscuit,Chocolate,Milk,Toothbrush,Flour,Soap"

Customer2,"Jean,Shirt,Flour, Shoes,Soap"

Cutomer3,"Biscuit, Bread"

];

NoConcatenate

main:
LOAD
Group_Id,
SubField(Items,',') as Items,
RecNo() as Rank
Resident Source_Data;

Drop Table Source_Data;

However, the above is script is giving results like this:

basavaraju_S_1-1607504232826.png

 

I know I can use Rank function in the front-end to get what I want, however the data that I have is about 10M rows, Hence I would Like to rank in the load script. Please help. 

 

Below is the output I am looking for:

basavaraju_S_0-1607504755258.png

 

 

 

Labels (1)
2 Solutions

Accepted Solutions
chrismarlow
Specialist II
Specialist II

Hi,

Try changing the second part to;

main:
Load
	If(RecNo()=1,1,
		If(Peek(Group_Id)=Group_Id,
			Peek(Rank)+1,1)) AS Rank,
	*;
LOAD
Group_Id,
SubField(Items,',') as Items
Resident Source_Data;

Cheers,

Chris.

View solution in original post

Taoufiq_Zarra

@basav  Maye be like this :

Source_Data:

Load * Inline [

Group_Id,Items

Customer1,"Bread,Biscuit,Chocolate,Milk,Toothbrush,Flour,Soap"

Customer2,"Jean,Shirt,Flour, Shoes,Soap"

Cutomer3,"Biscuit, Bread"

];

NoConcatenate

main:
load *,if(peek(Group_Id)=Group_Id,peek(rank)+1,1) as rank;
LOAD
Group_Id,
SubField(Items,',') as Items

Resident Source_Data;

Drop Table Source_Data;

 

output:

Taoufiq_Zarra_0-1607505274155.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

3 Replies
chrismarlow
Specialist II
Specialist II

Hi,

Try changing the second part to;

main:
Load
	If(RecNo()=1,1,
		If(Peek(Group_Id)=Group_Id,
			Peek(Rank)+1,1)) AS Rank,
	*;
LOAD
Group_Id,
SubField(Items,',') as Items
Resident Source_Data;

Cheers,

Chris.

Taoufiq_Zarra

@basav  Maye be like this :

Source_Data:

Load * Inline [

Group_Id,Items

Customer1,"Bread,Biscuit,Chocolate,Milk,Toothbrush,Flour,Soap"

Customer2,"Jean,Shirt,Flour, Shoes,Soap"

Cutomer3,"Biscuit, Bread"

];

NoConcatenate

main:
load *,if(peek(Group_Id)=Group_Id,peek(rank)+1,1) as rank;
LOAD
Group_Id,
SubField(Items,',') as Items

Resident Source_Data;

Drop Table Source_Data;

 

output:

Taoufiq_Zarra_0-1607505274155.png

 

Regards,
Taoufiq ZARRA

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

(you can mark up to 3 "solutions") 😉
basav
Creator
Creator
Author

@Taoufiq_Zarra @chrismarlow Both of your solution works thank you.