How to Apply All Combinations of 3 Columns in Excel

Method 1 – Use Power Query

Steps:

  • Create 3 separate tables for 3 columns. Select the first column and press Ctrl+T.

Use power query to apply all combinations of 3columns in Excel

  • Create Table window will appear. Press Enter.

Use power query to apply all combinations of 3columns in Excel

  • The Number column is now turned into a table.

  • Make the Color column a table. Select the Color column.

Use power query to apply all combinations of 3columns in Excel

  • Press Ctrl+T.
  • Press Enter.

Use power query to apply all combinations of 3columns in Excel

  • Turn the last column into a table.

  • Create a connection for each column.
  • Go to the Data tab and select From Table/Range.

Use power query to apply all combinations of 3columns in Excel

  • Power Query Editor window will open with the data of the first column.

Use power query to apply all combinations of 3columns in Excel

  • Right-click Table 1 and click Rename.

  • Rename the table. We renamed it Number.

Use power query to apply all combinations of 3columns in Excel

  • In the Home tab, click Close & Load.
  • Select Close & Load To.

Use power query to apply all combinations of 3columns in Excel

  • A dialogue box will open. Select Only Create Connection and press OK.

  • Follow the same procedure to add the Color column in Power Query Editor.

Use power query to apply all combinations of 3columns in Excel

  • Create a connection for this column as well.

Use power query to apply all combinations of 3columns in Excel

  • Follow all the steps for the Category column to add it to Power Query Editor.

Use power query to apply all combinations of 3columns in Excel

  • Create a connection in the Import Data dialogue box.

Use power query to apply all combinations of 3columns in Excel

  • Create temporary columns.
  • Click Get Data in the Data, and select Launch Power Query Editor.

Use power query to apply all combinations of 3columns in Excel

  • Select the Number, go to Add Column, and click Custom Column.

Use power query to apply all combinations of 3columns in Excel

  • Create a column name for the new helper column. We named it Temporary.
  • In the custom column formula, write “= 1”.
  • This column name and formula must be the same for all 3 columns.

Use power query to apply all combinations of 3columns in Excel

  • Press OK, and you will see a temporary column beside the Number column.

  • Create a temporary column beside the Color column.

Use power query to apply all combinations of 3columns in Excel

  • Follow the same procedure for the Category column.

  • Merge the columns.
  • Click Merge Queries. Select Merge Queries as New.

Use power query to apply all combinations of 3columns in Excel

  • A pop-up box will appear. In the pop-up, choose the Number and the Color column and select the Temporary column.
  • Select Full Outer (all rows from both) in the Join Kind option.
  • Click OK.

Use power query to apply all combinations of 3columns in Excel

  • The Number and the Color table are merged and saved as Merge 1.

Use power query to apply all combinations of 3columns in Excel

  • Merge the Category table with the Merge 1 table.
  • Choose Merge 1 and Category and select the Temporary column.
  • Select Full Outer (all rows from both) in the Join Kind option and hit Enter.

  • See that all three columns are merged with the Temporary column.

Use power query to apply all combinations of 3columns in Excel

  • Find all the combinations of these 3 columns.
  • Click the Color drop-down and select the Color option to expand the combinations.
  • Uncheck the box. Use the original column name as a prefix.
  • Press Enter.

Use power query to apply all combinations of 3columns in Excel

  • Click on the Color 1 drop-down.
  • Uncheck the box of null.

  • Follow the same steps for Category to expand the combinations and remove null rows.

Use power query to apply all combinations of 3columns in Excel

  • Unchecking null removes the empty rows in the combinations.

Use power query to apply all combinations of 3columns in Excel

  • Have all 24 combinations of the 3 columns.

Use power query to apply all combinations of 3columns in Excel


Method 2 – Combination of IFERROR, INDEX, and COUNTA Functions

Steps:

  • Create a column named All Combinations.
  • Type the following formula in cell E5.
=IFERROR(INDEX($B$5:$B$8,INT((ROW(1:1)-1)/((COUNTA($C$5:$C$7)* (COUNTA($D$5:$D$6)))))+1)&"-"&INDEX($C$5:$C$7, MOD(INT((ROW(1:1)-1)/COUNTA($D$5:$D$6)), COUNTA($C$5:$C$7))+1)&"-"&INDEX($D$5:$D$6, MOD((ROW(1:1)-1),COUNTA($D$5:$D$6))+1),"")
Formula Breakdown

COUNTA($D$5:$D$6))+1) looks into cells D5 and D6 and counts the number of information.

INDEX($D$5:$D$6,MOD((ROW(1:1)-1),COUNTA($D$5:$D$6))+1) returns a value or the reference to a value from cell D5 to D6.

INT((ROW(1:1)-1)/((COUNTA($C$5:$C$7)*(COUNTA($D$5:$D$6)))))+1) returns an integer value after dividing the number of “rows-1” by the product of the number of information in cell C5 to C7 and D5 to D7.

=IFERROR(INDEX($B$5:$B$8,INT((ROW(1:1)-1)/((COUNTA($C$5:$C$7)*(COUNTA($D$5:$D$6)))))+1) evaluates the formula and returns all possible combinations.

Use IFERROR, INDEX and COUNTA functions to apply all combinations of 3columns in Excel

  • Press Enter, and see the first combination.

  • Drag the bottom right corner of cell E5 to copy the formula to all cells.

Use IFERROR, INDEX and COUNTA functions to apply all combinations of 3columns in Excel

  • Once all the combinations are complete, you’ll start getting empty cells. Stop dragging when you get the first empty cell.

Use IFERROR, INDEX and COUNTA functions to apply all combinations of 3columns in Excel

  • Find all the combinations of the 3 columns in your Excel sheet.

Use IFERROR, INDEX and COUNTA functions to apply all combinations of 3columns in Excel


Method 3 – Run a VBA Code

Steps:

  • Create a column named All Combinations.

  • Press Alt+F11 to open the Microsoft Visual Basic window.

Run a VBA code to apply all combinations of 3columns in Excel

  • Select Module in the Insert tab to open a module.

  • Copy the following VBA code in the module.
Sub AllCombinations()
    i = 5
    For Each cella In ThisWorkbook.ActiveSheet.Range("B5:B8")
    .SpecialCells (xlCellTypeConstants)
    For Each cellb In ThisWorkbook.ActiveSheet.Range("C5:C7")
    .SpecialCells (xlCellTypeConstants)
    For Each cellc In ThisWorkbook.ActiveSheet.Range("D5:D6")
    .SpecialCells (xlCellTypeConstants)
    ThisWorkbook.ActiveSheet.Range("E" & i).Value = cella.Value
    ThisWorkbook.ActiveSheet.Range("F" & i).Value = cellb.Value
    ThisWorkbook.ActiveSheet.Range("G" & i).Value = cellc.Value
    i = i + 1
    Next
    Next
    Next
End Sub

Run a VBA code to apply all combinations of 3columns in Excel

  • Press F5 to run the VBA code.
  • Go back to the worksheet and get all the combinations of three columns.

Run a VBA code to apply all combinations of 3columns in Excel


Things to Remember

  • Don’t forget to provide proper cell references, or you won’t get the desired results.
  • Ensure the temporary column in the Power Query has the same name for all 3 columns.

Download Practice Workbook

Download this practice workbook while you are reading this article.


Related Articles


<< Go Back to Excel COMBIN Function | Excel Functions | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Alif Bin Hussain
Alif Bin Hussain

Alif Bin Hussain earned a BSc in Civil Engineering from Bangladesh University of Engineering and Technology. As an engineering graduate, he has a deep passion for research and innovation. He loves to play with Excel. In his role as an Excel & VBA Content Developer at ExcelDemy, he not only solves tricky problems but also shows enthusiasm and expertise in handling tough situations with finesse, emphasizing his dedication to delivering top-notch content. He is interested in C, C++,... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo