In Excel, Expand All Combinations of Multiple Columns

esProc DesktopesProc Desktop
3 min read

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.

ABCDEFG
1Assembly#ProductTypeUnit ConfigNominal CapacitySupply VoltageGenerationCase Construction
23H1012290001CMD,P24,36FAA,B
33H1012290002CMD,P48,60FA,BA,B
43H1012290003CMD,P24,36B,C,D,EAA,B

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:

ABCDEFG
6Assembly#ProductTypeUnit ConfigNominal CapacitySupply VoltageGenerationCase Construction
73H1012290001CMD24FAA
83H1012290001CMD24FAB
93H1012290001CMD36FAA
103H1012290001CMD36FAB
113H1012290001CMP24FAA
123H1012290001CMP24FAB
133H1012290001CMP36FAA
143H1012290001CMP36FAB

Solution:

Use SPL XLL to enter the following formula:

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

As shown in the picture below:

r/esProc_Desktop - In Excel, Expand All Combinations of Multiple Columns

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 "";"".

SPL XLL is now FREE to download and ready to make your Excel tasks a breeze! Try it now: http://www.scudata.com/download-Desktop

10
Subscribe to my newsletter

Read articles from esProc Desktop directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

esProc Desktop
esProc Desktop

esProc Desktop is a desktop data processing & analytics tool and is specifically designed for ordinary business people. It supports complex computations & spreadsheet data manipulation, can deal with tasks that are hard to accomplish in Excel, and in addition, generates more concise code than VBA and Python. esProc Desktop boasts all-around programming capabilities, supports multi-step interactive data analytics and is easy to use without configurations. This significantly lowers the technical threshold for data analytics.