Power Query: Faster Fiddly Fill Down
8 July 2020
Welcome to our Power Query blog. This week, I look at a more efficient method to solve last week’s fill down problem.
I start with the same data as last week.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/188/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I would like to get this into a more standard format, by filling down the tent and awning types. I begin by extracting my data to Power Query by using the ‘From Table’ option on the ‘Get & Transform’ section of the Data tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/188/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
Instead of creating a new column, as I did last week, I am going to use ‘Replace Values’ to fix my data in the Awning column. I start by creating a ‘Replace Values’ step. At this point it doesn’t matter what I am replacing, I just need to have the format of the M code I will need.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/188/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I have ticked the box in the ‘Advanced options’ to ‘Match entire sell contents’. The M code I have generated is:
= Table.ReplaceValue(#"Changed Type","First","Second",Replacer.ReplaceValue,{"Awning"})
If I hadn’t matched the entire cell contents, then the Replacer parameter would have been ReplaceText instead of ReplaceValue. Also:
- instead of First, I am going to use each[Awning], i.e. the current Awning value
- instead of Second, I am going to use a condition: this will be the same condition that I used in last week’s conditional column, which, in M code, is:
each if [Tent] = null then [Awning] else “Don’t Fill”.
This all means, keep the Awning value if Tent is null, otherwise put ‘Don’t Fill’ in the Awning value. The M code for my step is now:
= Table.ReplaceValue(#”Changed Type”, each [Awning], each if [Tent] = null then [Awning] else “Don’t Fill”, Replacer.ReplaceValue,{"Awning"})
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/188/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
When I click on the check mark to execute my code I see my results:
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/188/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
Similarly to last week, I can select Tent and Awning and fill them both down.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/188/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
All I need to do now, is replace ‘Don’t Fill’ with null in Awning.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/188/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
My columns are now filled correctly. Next time, I will look at another method which copies a column to get the required result.
Come back next time for more ways to use Power Query!