Forum Discussion
Query editor replacing values based on another column
- 9 years ago
You are right. I was confusing Table.ReplaceValues with Table.TransformColumns. :smileyembarrassed:
My solution works though, but the code you are looking for:
#"Replaced Value" = Table.ReplaceValue(#"Replaced OTH",each [Gender],each if [Surname] = "Manly" then "Male" else [Gender],Replacer.ReplaceValue,{"Gender"})Edit: it seems you switched "old" and "new" in your cide.
Edit: wrong answer:
You can't replace values in a column based on values in another column.
Instead, create an additional column and replace the existing column with the new column.
Adjusted part of the code:
#"Replaced OTH" = Table.ReplaceValue(#"Promote Header"," ","OTH",Replacer.ReplaceValue,{"Gender"}),
#"Added Custom" = Table.AddColumn(#"Replaced OTH", "Custom", each if Text.Contains([Surname],"Manly") then "Male" else [Gender]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Gender"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Gender"}})
in
#"Renamed Columns"
- spoony9 years agoHelper I
ok thanks that seem to work but i was checking this website and it shows someone got it to work. Is this not M power query?
- MarcelBeug9 years agoCommunity Champion
You are right. I was confusing Table.ReplaceValues with Table.TransformColumns. :smileyembarrassed:
My solution works though, but the code you are looking for:
#"Replaced Value" = Table.ReplaceValue(#"Replaced OTH",each [Gender],each if [Surname] = "Manly" then "Male" else [Gender],Replacer.ReplaceValue,{"Gender"})Edit: it seems you switched "old" and "new" in your cide.
- Anonymous7 years agoNot applicable
Thanks for this code :):
#"Replaced 68 to 680" = Table.ReplaceValue(#"Replaced H1353",each [Payroll Reference Number],each if [Reporting Unit] = "Store5" and [Payroll Reference Number] = "68" then "680" else [Payroll Reference Number],Replacer.ReplaceValue,{"Payroll Reference Number"}),I wanted to ammend an individual Payroll Number, based on the Store Name!
Experienced the issue whereby two people from different stored were given the same payroll number.
However, i did not want to create a new Payroll Number column, as most other people suggested.
So once again, thanks :)