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.
Thanks..
I understand it's an exact match. That's why it's frustrating when the replacement isn't working when it's matched exactly. I tried formatting as text already, and I am very sure that there are not any hidden characters. Just to be sure, I changed the column type to text, cleaned and trimmed it, and it still did not work. The leading zero is in the string to be replaced. It just simply will not replace this one value when it works completely fine for over 60 others, some of which have leading zeros.
- srlabhe1 year ago
Super User
How about adding the data in PBIX only and create separate table with Original Value and Replaced Value and then join it with original table ?
- Adamp19161 year ago
Helper I
This would likely work.
Some of the values in the column also contain alpha characters, so I can't just change the type to "Whole Number" and just remove all leading zeros so the replacement string doesn't mess up. I don't particularly care to include those, so I think I may just end up creating a custom column that only keeps numeric characters and then format as whole number. That would remove all leading zeros and then the replacement should work since it wouldn't have to consider them anymore.
What's absurdly frustrating about this approach is now I need to adjust all of the replacement steps to run on the new column.
This all seems like an extremely convoluted way to just replace what I enter how I enter it, which excel does just fine in a matter of seconds.
Some of the Power BI functionality is really just odd... Extremely basic and simple tasks should be just that...
- srlabhe1 year ago
Super User
If you have the list of original values with its replacebale values in excel. Then just copy that -> goto Add Data and paste there.You rename the column headers as per you rneed