Please note javascript is required for full website functionality.

Blog

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.

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.

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.

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’.

Next, I create two conditional columns, by using the ‘Conditional Column’ option on the ‘Add Column’ tab:

and a second:

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.

I have my two columns, and now I can complete the values in Tent Size by right-clicking and choosing to fill down.

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.

I filter using the ‘Text Select’ option, and choose to keep those rows which are not null.

I can delete the column Tent Type which is now a duplicate of Tent Size and Colour, and reorder my columns:

My tent data is now in the format that I need.

Come back next time for more ways to use Power Query!

Newsletter