In Excel, Expand All Combinations of Multiple Columns

Judith-Excel-Sharing - Jun 12 - - Dev Community

Problem description & analysis:

In the following Excel table, column A contains codes and the other columns are grouping columns having different meanings and containing comma-separated values.

table 1

The computing goal: split each grouping column value to generate a row for each unique combination. Below is the expansion result of the first record:

expansion result of the first record

Solution:

Use SPL XLL to enter the following formula:

=spl("=E@b(?.(~.(~.split@c())).conj(eval($[xjoin(] / ~.($[~(] / # / $[)]).concat($[;]) / $[)])))",A2:G4)

Enter fullscreen mode Exit fullscreen mode

As shown in the picture below:

result table with code entered
Explanation:

E@b()function converts each row, except for the column header row, to a sequence. split@c splits a string into a comma-separated sequence. conj() function concatenates members of each sequence. eval()function takes the string as the dynamic code to execute. xjoin() performs cross-product on multiple sequences to combine them. $[;] is the simplified form of writing a string, which is equivalent to "";"".

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .