Power Query: Unique Combination
28 August 2019
Welcome to our Power Query blog. Today, I look at a way to create a set of data from multiple tables.
I have some simple lists of data for my ever-ready fictional salespeople.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I want to create a table which provides me with all the combinations, ready for the amounts to be filled in. An example row would be ‘Mary Hotel London’.
I start by creating a table of my employees from the ‘From Table’ option in ‘Get & Transform’ in the ‘Data’ tab:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
This loads my data into a query
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I repeat this process, so that I have three queries, namely ‘Employees’, ‘Expense Types’ and ‘Locations’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
In each case, I have chosen to only create a connection when I saved my queries.
The first method I will use is to merge queries together. If I tried this now, the problem becomes obvious:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
I don’t have a column that I can use to connect my tables: I need to create one.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
For each of my queries, I am going to create a custom column from the ‘Add Column’ tab
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
I am going to set all rows in my new column, Link, to have the same value of zero (0). I will add the column to all my queries.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
Now when I merge, I have a column I can use to join my data up. If I use a full outer join, I can join each row in my first query to each row in my second query.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
I can see that each employee name has been linked to all the expense types. I expand the Expense Type column and rename my query.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
I only need the expense type, not the linking column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image11.png/22c6daeb82d7d69ac88f878227e04b28.jpg)
Now I can merge this with the locations using a similar method.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image12.png/a1537847463e660a31158c8032525438.jpg)
This gives me all the combinations I require, and I can delete the Link column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image13.png/917da985be13220165c8d2823e95344f.jpg)
There is, however, a quicker way.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image14.png/8c3be7af9f73d031acae69ed85a2e148.jpg)
I have created three new queries from my original data. This time I don’t add the link column. My new queries are ‘Employees_No_Link’, ‘Expense_Types_No_Link’ and ‘Locations_No_Link’. I go into ‘Employees_No_Link’:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image15.png/e63c0a4c21afc9afb438aacc09a59317.jpg)
I create a custom column again, but this time instead of a fixed value, I use the name of the query ‘Expense_Types_No_Link’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image16.png/d082e3477129350b8a2a589156028e63.jpg)
In a similar way to the merge operation from the original method, I have created a column of tables, which may be expanded.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image17.png/a468c9c28195e8f18fdedfa59a0cf042.jpg)
I repeat this process for the locations.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image18.png/61935f470d8b9f21b7b7683ffca40895.jpg)
When I expand Link_Locations, I get my result:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/143/image19.png/06909e3fbfc8faf87de7555c0b99e9d3.jpg)
Come back next time for more ways to use Power Query!