Forum Discussion
Replace Values is not working
- 1 year ago
I found the problem. It's the leading zeros. Power BI can't handle them with Replace Values because it automatically removes them in the M string. Even when you manually put them back in, it still doesn't correctly handle them.
I ended up just making a new column and doing this in Power Query to remove the non-numeric characters.
Text.Remove( [DT Number], { Character.FromNumber(32) .. Character.FromNumber(47), Character.FromNumber(58) .. Character.FromNumber(255) } )where [DT Number] is the original column. Then I formatted the column as whole number to just remove the leading zeros from the values being replaced. But, since Replace Values can't be entered as a non-numeric value when the column is formatted as whole number, you need to reformat again back to text. Then I used the new column to replace all the values and updated the reference in each visual to the new column.
This solution works, but it is still absolutely ridiculous that you can't just replace a value with a leading zero directly. Excel has been able to do that with no issues for literal decades.
Hi Adamp1916
Replace Values is exact-match. That stubborn code almost always has a hidden character. The apostrophe you see is just Excel’s “stored as text” marker, not the real value. In Power Query do this:
-
Change the column type to Text.
-
Transform > Format > Clean, then Trim. Try Replace Values again.
-
If it still won’t match, normalize first: add a custom column
NormalizedCode = Text.PadStart(Text.Select([Code], {"0".."9"}), 5, "0")
Then run Replace Values on NormalizedCode.
This fixes leading-zero issues and invisible characters, so the replace works.