Forum Discussion
Replace null values with contents from another column
- 9 years ago
Yes. Select Add Column and then write an if statement something like this (it is case sensitive)
= if [column 1] = null then [column 2] else [column 1]
- 9 years ago
Saw this old post and found another solution, so I thought I would share.
You can modify the "M" code if you are not looking to add a column/ delete the old one.
=Table.ReplaceValue(#"Last Step",null, each _[Values Column],Replacer.ReplaceValue,{"Null Column"})
#"Last Step" being the previous step in your query
[Values Column] being the column that has the values in it to replace the nulls
"Null Column" being the column with the null values
Be sure to use the " each _[Values Column]" syntax with the spaces before and after "each", otherwise you will get an error.
Here is the original video from Miguel Escobar.
Cheers!
**NOTE: When I have used this, it changed all the data types in my query to "Any". I asked Miguel, and he reached out to MS to see if it is a bug or if it is intentional. If you are using it early in your query before you change your data types, might still be useful. Otherwise you can change your data types back. Just a fair warning!
FYI, it seems the data type change bug is no there, I'm not having any issues with that currently.
Thank you for the input! So quick question, only the null values are replaced, not all the fields that have no null values correct?