Power Query: Part Time
27 January 2021
Welcome to our Power Query blog. This week, I look at adding rows to existing data in order to present a complete picture.
I have some data for parts for my imaginary tent business.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
It shows me how many parts of a particular type that were required, but there are no rows if the parts required were zero. I want to have a row for each part and date combination, even if the required quantity was zero.
To do this, I begin by uploading my data to Power Query. I use ‘From Table’ on the ‘Get & Transform’ section of the Data tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
I accept the defaults for the ‘Create Table’ dialog.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I want to view my data in date order, so I sort on the Date column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
I can do this by selecting the Date column and using the icon next to the title. I choose to ‘Sort Ascending’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
I then do the same thing for Part Number.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
I would like to generate rows for the part numbers to show when there was no demand. There are a number of ways to do this, but I will create a query to link to. This new query will be a matrix, linking all dates to all part numbers in my query.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
I create a new query just for the Date column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
I then choose to remove duplicates, so that I have a list of unique dates.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
I go back to the original query and do the same for Part Number.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
I want to combine my two new queries, so I convert Part Number to a table. I will add the data from the list query Date to my Part Number table.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image11.png/22c6daeb82d7d69ac88f878227e04b28.jpg)
On the ‘Add Column’ tab, I choose to add a custom column. In the formula box for this column, I enter the list query Date.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image12.png/a1537847463e660a31158c8032525438.jpg)
This creates a new column where each value is a list. If I click in the space next to each list, I can see the contents. I need to expand the list.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image13.png/917da985be13220165c8d2823e95344f.jpg)
I choose to expand to new rows, as my aim is to create a matrix where each date links to each part number.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image14.png/8c3be7af9f73d031acae69ed85a2e148.jpg)
I have my matrix, and for clarity, I rename my columns and change the data type of Date to date / time. I can link this matrix query to my original query, to fill in the values that I have for Quantity Required.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image15.png/e63c0a4c21afc9afb438aacc09a59317.jpg)
From the Home tab, I select ‘Merge Queries’. I choose to merge this with my original query and link on Part Number and Date. I choose a left outer join.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image16.png/d082e3477129350b8a2a589156028e63.jpg)
I need to expand the new column; I will only need the quantity column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image17.png/a468c9c28195e8f18fdedfa59a0cf042.jpg)
I choose to only extract Quantity Required, and to keep that column name.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image18.png/61935f470d8b9f21b7b7683ffca40895.jpg)
I want to show all the null values as zeroes.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image19.png/06909e3fbfc8faf87de7555c0b99e9d3.jpg)
I right click on Quantity Required and choose to ‘Replace Values’. I opt to replace null with zero [0].
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/217/image20.png/173ef895b62ce391674d271b99c4d178.jpg)
I reorder my columns and sort on Date and then Part Number. I have my data in the required format at long last!
Come back next time for more ways to use Power Query!