Forum Discussion
How to replace value with conditional?
- 1 year ago
Hi Anonymous ,
= Table.ReplaceValue( YourTable, each _, each if _ = "zero cost" then _ else null, Replacer.ReplaceValue )This M code transforms the Cost column by replacing any numeric value with null, while keeping the text "zero cost" unchanged.
Best regards,
- Anonymous1 year ago
Hi Anonymous
You can try the following
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",each [Zero Cost],each if [Zero Cost]<>"zero cost" then null else [Zero Cost] ,Replacer.ReplaceValue,{"Zero Cost"})and the solution DataNinja777 is right, you can also refer to it.
#"Replaced Value1"=Table.ReplaceValue( #"Replaced Value", each _, each if _ = "zero cost" then _ else null, Replacer.ReplaceValue )If the solutions DataNinja777 and i offered help you solve the problem, you can consider to accept them as solutions.
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
My query is opposite, any nemeric values or any other values need to be null and only 'Zero cost' should be remained as 'Zero cost'.
Hi Anonymous
You can try the following
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",each [Zero Cost],each if [Zero Cost]<>"zero cost" then null else [Zero Cost] ,Replacer.ReplaceValue,{"Zero Cost"})
and the solution DataNinja777 is right, you can also refer to it.
#"Replaced Value1"=Table.ReplaceValue(
#"Replaced Value",
each _,
each if _ = "zero cost" then _ else null,
Replacer.ReplaceValue
)
If the solutions DataNinja777 and i offered help you solve the problem, you can consider to accept them as solutions.
Best Regards!
Yolo Zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.