Power Query: Reorganising by Numbers
18 March 2020
Welcome to our Power Query blog. This week, I look at using some numerical functions to sort out expense formatting.
I have more expense data from my imaginary salespeople. I need to format it so that I have my data in separate columns.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
As usual, my first step is to extract the data to Power Query, using the ‘From Table’ option in the ‘Get & Transform’ section of the Data tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
The first thing I notice is that Power Query has generated a ‘Changed Type’ step, which sets the column type to Any. As this doesn’t achieve anything, I remove this step by clicking the X next to it.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I need a way of distinguishing between the rows, so I add an index from the ‘Add Column’ tab. I will start my index at zero (0).
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
Since my data is in groups of five (5) rows, I can use another feature on the ‘Add Column’ tab, which is in the Standard dropdown of ‘From Number’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
Using ‘Integer-Divide’, I want to divide this Index column such that I retain only the integer part of the division result:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
I choose to divide by five (5) and click ‘OK’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
I now have a column which counts my rows, and a column which identifies each group of data. I combine these by using the mod functionality. I will transform my Index column using the Modulo option in the Standard options in the ‘From Number’ section on the Transform tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
I need to specify the value to use, which again is five (5), since that is the size of each data group.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
I click ‘OK’ to see the changes to my Index column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
I now have each line in my data group numbered. I can use this to pivot my data. First, I move Integer Division to the first column place.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image11.png/22c6daeb82d7d69ac88f878227e04b28.jpg)
Second, I can select my Index column, and choose to ‘Pivot Column’ from the ‘Any Column’ section of the Transform tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image12.png/a1537847463e660a31158c8032525438.jpg)
I want to use the values in Details, and I don’t need to aggregate them in any way.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image13.png/917da985be13220165c8d2823e95344f.jpg)
This is looking more promising. I just need to tidy up my data by removing excess columns and by renaming my remaining columns.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/172/image14.png/8c3be7af9f73d031acae69ed85a2e148.jpg)
My data is now in a format where I can merge it with other expense data.
Come back next time for more ways to use Power Query!