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: 
rajeshqvd
Creator II
Creator II

Display Top 3 values with comma separated

Hi,

Need to Display Top 3 values with comma separated Thanks.

INPUT:

IDSale
111454
11154
11154
11121
11112
111121
2221
22212
22215
222121
22251
33321
333212
33315
3331541
333454

 

Required Output:

IDSale
111454,121,54
222121,51,15
3331,541,454,212
Labels (1)
1 Solution

Accepted Solutions
Gysbert_Wassenaar

See attached example


talk is cheap, supply exceeds demand

View solution in original post

7 Replies
prat1507
Specialist
Specialist

Tab:
Load * Inline [
ID, Sale
111, 454
111, 54
111, 54
111, 21
111, 12
111, 121
222, 1
222, 12
222, 15
222, 121
222, 51
333, 21
333, 212
333, 15
333, 1541
333, 454
];

NoConcatenate Tab2:
LOAD *,
if(ID= Previous(ID), Peek('Rank')+1,1) as Rank
Resident Tab
Order by ID,Sale desc;

NoConcatenate Tab3:
Load ID, Concat(Sale,',') as Sale
Resident Tab2 where Rank<=3
Group by ID
;

sankarraja
Partner - Contributor
Partner - Contributor


Tab1:
NoConcatenate
LOAD *,
if(ID= Previous(ID), Peek('Rank')+1,1) as Rank
Resident Tab
Order by ID,Sale desc;
drop table Tab;

Tab2:
NoConcatenate
Load ID,Sale,Rank
Resident Tab1 where Rank<=3;
drop table Tab1;

Tab3:
NoConcatenate
Load ID, Concat(Sale,',') as Sale
Resident Tab2
Group by ID;
drop table Tab2;

 

Gysbert_Wassenaar

Like this:

Result:
LOAD ID, Left(SalesList,Index(SalesList,',',3)-1) as Sale;
LOAD ID, Concat(Sale,',', -Sale) as SalesList GROUP BY ID;
Load DISTINCT* Inline [
ID, Sale
111, 454
111, 54
111, 54
111, 21
111, 12
111, 121
222, 1
222, 12
222, 15
222, 121
222, 51
333, 21
333, 212
333, 15
333, 1541
333, 454
];

talk is cheap, supply exceeds demand
rajeshqvd
Creator II
Creator II
Author

Sorry for wrong post please help to get below output

Input:

IDSale
111 blue
111 blue
111 blue
111 red
111 red
111 green
111green
111green
111white
222 blue
222 blue
222 blue
222 red
222 red
222 red
222 red
222white
222green
222white
333 black
333 black
333 black
333 white
333 white
333green
333green
333green
333red

 

Required Output:

IDSale
111blue,red,green
222red,blue,White
333Black,green ,white

 

Gysbert_Wassenaar

What if there are five unique colors for an ID? What's the Top 3 then? How do you rank your colors? Is blue larger than red or is red larger than blue?


talk is cheap, supply exceeds demand
rajeshqvd
Creator II
Creator II
Author

Based on count group by ID
Gysbert_Wassenaar

See attached example


talk is cheap, supply exceeds demand