Power Query: Conditional Column Splitting
30 January 2019
Welcome to our Power Query blog. This week, I look at an example where one column contains both header and detail data.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I have some tent data where the Tent Type column contains both header data, the tent size, and more detailed data, size and colour. I want to extract that data into two columns so that I have a size column, and a size and colour column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
My first step is to create a query by selecting ‘From Table’ on the ‘Get & Transform’ section of the ‘Data’ tab. The ‘Create Table’ box appears so that I can check the position of my table and indicate if there are headers.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
In order to format my Price column correctly, I replace the nulls with zero (0), by right-clicking with the Price column selected and choosing the option ‘Replace Values’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
Next, I create two conditional columns, by using the ‘Conditional Column’ option on the ‘Add Column’ tab:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
and a second:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
Since the price is zero if Tent Type holds the tent size rather than the size and colour, I can use the value of Price to determine how to populate my new columns.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
I have my two columns, and now I can complete the values in Tent Size by right-clicking and choosing to fill down.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
I can now remove the rows where Price is zero or Tent Size and Colour is null by filtering on one of these columns – I choose Tent Size and Colour.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
I filter using the ‘Text Select’ option, and choose to keep those rows which are not null.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image11.png/22c6daeb82d7d69ac88f878227e04b28.jpg)
I can delete the column Tent Type which is now a duplicate of Tent Size and Colour, and reorder my columns:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2019/power-query/113/image12.png/a1537847463e660a31158c8032525438.jpg)
My tent data is now in the format that I need.
Come back next time for more ways to use Power Query!