Power Query: Step Back and See
7 August 2019
Welcome to our Power Query blog. Today, I build a function to add a column to a table.
My imaginary salesperson, Mary, has been busy, and I want to look at how her commission varies daily.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I upload my data into Power Query using ‘From Table’ on the ‘Get & Transform’ section of the Data tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
I am going to add an index column, in the ‘Add Column’ tab:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I choose to start from 0.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
The step is call ‘Added Index’, which I need to remember for later. I am going to add another index column, this time starting at 1:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
I am going to merge ‘Added Index’ and’ Added Index.1’ by using some M code in a step. This will allow me to link each row to the previous row. The M function I am using is Table.NestedJoin(), which I used in Power Query: Group Dynamics when I was calculating group share.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
The M code I have used is:
= Table.NestedJoin(#"Added Index", {"Employee","Index"}, #"Added Index1", {"Employee","Index.1"}, "Added Index", JoinKind.LeftOuter)
This takes my data with the index that begins at 0 and links it to the table with the index that begins at 1. Therefore, it links all the data to the previous row.
Next, I need to expand some data from my joined table.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
In this case, I will ‘Use original column name as prefix’, so I can distinguish between my original and expanded data.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
I can now remove the row with null values. I choose to apply a filter.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
Now, I create a custom column to calculate the daily difference in commission.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
I click OK to see my new column:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image11.png/22c6daeb82d7d69ac88f878227e04b28.jpg)
I can track my salesperson’s progress in terms of commission, and set targets if I wish.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/140/image12.png/a1537847463e660a31158c8032525438.jpg)
I can expand this method to include data from other salespeople.
Come back next time for more ways to use Power Query!