Given two separate lists of items, how can you create a list of all possible combinations from those lists? In this post, I’ll show you how this can be done using power query.

List1-and-List2-Tables How To Generate All Possible Combinations Of Items From Two Lists

In this example I’ve set up two lists and created tables from them called List1 and List2.

Create a Connection Only Query for the Two Lists

For each table, we’re going to create a connection only query that adds a column with the same constant value in each row. We will then use this column to join our two tables together using a merge query.

Combination-Of-Items-From-Two-Lists-Create-Query-from-Table How To Generate All Possible Combinations Of Items From Two Lists

Select a cell in your list and then go to the Data tab and select the From Table/Range command in the Get & Transform Data section.

Combination-Of-Items-From-Two-Lists-Add-Custom-Column How To Generate All Possible Combinations Of Items From Two Lists

From the query editor go to the Add Column tab and select Custom Column from the menu.

Combination-Of-Items-From-Two-Lists-Add-Custom-Column-with-Constant-Formula How To Generate All Possible Combinations Of Items From Two Lists

In the Custom Column dialog box add a constant formula. This can be any text or number, just make sure it’s the same in both list queries.

  1. Give your new column a name. I’ve named it Join Column.
  2. Add a constant to the Custom column formula. I’ve chosen 1 for my constant.
  3. Press the OK button.

Combination-Of-Items-From-Two-Lists-Close-and-Load-To How To Generate All Possible Combinations Of Items From Two Lists

Go to the Home tab in the query editor and press the lower part of the Close & Load button then select Close & Load To from the menu.

Combination-Of-Items-From-Two-Lists-Import-Data-Only-Create-Connection How To Generate All Possible Combinations Of Items From Two Lists

In the Import Data dialog box, select Only Create Connection and then press the OK button.

Repeat these steps for both lists. You should have two connection only queries called List1 and List2.

Join the Two Connection Only Queries with a Merge Query

Now we are ready to join these two lists together using a Merge query.

Combination-Of-Items-From-Two-Lists-Combine-Queries-with-Merge How To Generate All Possible Combinations Of Items From Two Lists

Go to the Data tab and select Get Data from the Get & Transform Data section. Select Combine Queries from the menu and then select Merge from the submenu.

Combination-Of-Items-From-Two-Lists-Create-Merge-Query How To Generate All Possible Combinations Of Items From Two Lists

Now we can set up our merge query to join the two lists.

  1. Select List1 for the first table.
  2. Left click on the Join Column created in connection only queries.
  3. Select List2 for the second table.
  4. Left click on the Join Column in the List2 connection only queries.
  5. Select the Join Kind as Full Outer (all rows from both).
  6. Press the OK button.

Combination-Of-Items-From-Two-Lists-Delete-Join-Column How To Generate All Possible Combinations Of Items From Two Lists

We can delete the Join Column now as we don’t really need it anymore and the output will be less cluttered if we remove it. Right click on the column heading and select Remove.

Combination-Of-Items-From-Two-Lists-Expand-the-List2-Table How To Generate All Possible Combinations Of Items From Two Lists

Now we can expand the List2 table in our query.

  1. Left click on the filter icon to the right of the column heading.
  2. Un-check the Join Column as we don’t need this in the query results.
  3. Un-check the Use original column name as prefix box. We don’t need this either.
  4. Press the OK button.

Combination-Of-Items-From-Two-Lists-Close-and-Load How To Generate All Possible Combinations Of Items From Two Lists

Now Close & Load the query from the Home tab.

Our List of All Possible Combinations

Combination-Of-Items-From-Two-Lists-Results How To Generate All Possible Combinations Of Items From Two Lists

Now we have a table which contains every possible combination of items from List1 and List2.

With small tables like this example, we could have easily created a table manually. For Large lists this query becomes a massive time saver though!

We can also iterate this process if we have more than two tables to find all possible combinations items from 3 or more lists.