Power Query: Next (Row) Once Again Please
26 February 2020
Welcome to our Power Query blog. This week, I look at yet another solution to my “February problem” referencing other rows.
John, my reliable imaginary salesperson, has been filling in data again. This time, I have some information on items purchased by customers in December:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
He has decided to combine the item and the description in the same column, so I need to move the description into a separate column and remove the extra rows. Unlike the data for last week, this time one of the item codes does not have a description on the next line, so the two previous approaches (detailed last week and the week before) won’t work.
This week, I look at a solution where I point to the table in the previous step.
I extract my data to Power Query using the ‘From Table’ option on the ‘Get & Transform’ section on the ‘Data’ tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
My first step is to add an index to the table; I can do this from the ‘Add Column’ tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I choose to start the index from zero (0).
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
I add a custom column from the ‘Add Column’ tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
My new Description column will point to the Item Code/ Description value for the next row if Customer is null on the next row.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
The M code I have used is:
= if #"Added Index"{[Index]+1} [Customer] = null then #"Added Index"{[Index]+1} [#"Item Code/Description"] else null
‘Added Index’ is the name of the previous step, and represents the table created at the previous step.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
This looks good; now I just need to remove the rows where Customer is null.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
Once I click ‘OK’, I should have all the data I need in each row.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
I ‘Close & Load’ my data to Excel.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/169/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
Come back next time for more ways to use Power Query!