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!
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]
- Anonymous3 years agoNot applicable
Hi Matt!
I wrote something like : if [Session Date] = null then "Not Passed" else if [Expiration Date] < Date.From(DateTime.LocalNow()) then "Expired" else if [Expiration Date] = null then [Status] else "Ok"
but in result column error values appeared in cells where should be Status columns values. Other cells according to formula.
Could you please help me to solve it?
- MattAllington3 years ago
Community Champion
I just wrote this in a test file, and it worked fine
each if [Session Date] = null then "Not Passed" else if [Exp Date] < Date.From(DateTime.LocalNow()) then "Expired" else if [Exp Date] = null then [Status] else "OK"
check that all your date columns are correctly formatted as Date before this step and that the Status column is correctly formatted as text
- Rogerforever3 years agoNew Member
Best!