Power Query: Pivot Problems
13 January 2021
Welcome to our Power Query blog. This week, I look at an example using a pivot.
I have some tent data, just for a change…
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I want to reorganise this data into separate columns for price, quantity and discount. I extract the data to Power Query by using ‘From Table’ from the ‘Get & Transform’ section of the Data tab. I am only interested in the main table, not in the title at the top of the sheet.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
I start by filling down on Tent so that all rows are populated. I can do this by selecting Tent and then right-clicking to select Fill and then Down.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I want to use ‘Pivot Columns’ from the Transform tab, as it will create new columns from the values in Property, which sounds like what I want.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
I know the values for these columns are in Amounts, and that I don’t want to aggregate this data in any way.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
When I try to pivot, I get an error, which was not the plan. I take a closer look at the problem.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
The error message tells me that ‘There were too many elements in the numeration to complete the operation’. I can see that the error only occurs with tent type ‘Wedding’, so I delete the ‘Pivoted Column’ step and look again at my data.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
I have two entries for tent type ‘Wedding’ with different Property values. Since Property is being pivoted, this is giving me duplicate errors. I need to distinguish between these two entries outside of the data being pivoted. I need a new column. I want to pull out the price of the tent and include that in my Tent column. I start by adding a conditional column from the ‘Add Column’ tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
I only want the amount to appear in my new column if it is the price of the tent.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
I can now fill down on this column as I did for Tent earlier.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
I will merge the Tent and Price columns from the Transform tab. The merge from the Transform tab does not keep the original columns, which is what I want in this particular case.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image11.png/22c6daeb82d7d69ac88f878227e04b28.jpg)
I select both columns in the order I want them to appear, and create an appropriate separator.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image12.png/a1537847463e660a31158c8032525438.jpg)
Now I can distinguish between the tents, so I pivot Property again.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/215/image13.png/917da985be13220165c8d2823e95344f.jpg)
This time I get my data in a format I can use.
Come back next time for more ways to use Power Query!