In Excel, Concatenate the Top 3 Members in Each Group into a String

In Excel, Concatenate the Top 3 Members in Each Group into a String

Problem description & analysis:

Below is a grouped table having detailed data under each group:

ABC
1ClientLocationSales
2ABCNew York5,000
3Florida4,000
4Texas3,000
5California2,000
6Georgia1,000
7XYZTennessee10,000
8New Jersey8,000
9Washington6,000
10New York4,000
11DEFOhio7,500
12Colorado5,000
13HIJVirginia8,000

We need to concatenate the top 3 locations in each group into a string with the comma and display them along with the group header.

EF
1ClientTop 3 Locaction
2ABCNew York,Florida,Texas
3XYZTennessee,New Jersey,Washington
4DEFOhio,Colorado
5HIJVirginia

Solution:

Use SPL XLL to enter the formula below:

=spl("=?.group@i(~(1)).([~(1)(1),~.top(-3;~(3)).(~(2)).concat@c()])",A2:C13)

As shown in the picture below:

r/esProc_Desktop - In Excel, Concatenate the Top 3 Members in Each Group into a String

Explanation:

group@i groups rows by the specified condition; ~(1) represents the 1st member of the current row. the top() function gets the top N members. concat@c concatenates members of a sequence with the comma.

SPL XLL is now FREE to download and apply. Come can try this solution on your own! It may inspire you a lot! http://www.scudata.com/download-Desktop