Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hi,
I want to replace values in a text column but matching only entire values.
That is, I want to match "CAPITAL FED" but not "CAPITAL FEDERAL" (it's Spanish 😉)
I tried to use Transform > Replace values in Power BI Desktop and enabled option "Match entire cell contents" but noticed that this causes Replacer.ReplaceText to change to Replacer.ReplaceValue in Power Query code, what doesn't match anything.
I think Replacer.ReplaceValue is for numeric values but no sure since its doc (https://docs.microsoft.com/en-us/powerquery-m/replacer-functions) is very poor
Bellow is the full code:
= Table.ReplaceValue(#"Otras columnas quitadas","CAPITAL FED","CAPITAL FEDERAL",Replacer.ReplaceValue,{"localidad"})
My question is why is the replacer changed and what is the solution to achieve the replacement (e. g. is there any way to use regular expresions?)
Thany you
Solved! Go to Solution.
@dlopez ,
Can you give some example of it? I tried here the option to Match entire cell contents, it worked.
Have you tried clean/trim this column before the replace ?
Hi,
I wrote some about the different between the two replacer functions. Replacer.ReplaceText also replaces substrings, whereas Replacer.ReplaceValue only matches the entire cell contents. If you like, I posted some screenshots in this article about the difference:
https://gorilla.bi/power-query/replace-values/#replacer-functions
Hope that helps!
Rick
--------------------------------------------------
@ me in replies or I'll lose your thread
Master Power Query M? -> https://powerquery.how
Read in-depth articles? -> BI Gorilla
Youtube Channel: BI Gorilla
If this post helps, then please consider accepting it as the solution to help other members find it more quickly.
Hi @dlopez ,
Based on this document, I think when columns have numeric or other types, it will use replacer.replacevalue. In addition, which part don't work? If possible, could you please inform me more detailed information(such as your expected output and your sample data (by OneDrive for Business))? Then I will help you more correctly.
Please do mask sensitive data before uploading.
Thanks for your understanding and support.
Best Regards,
Zoe Zhi
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@dlopez ,
Can you give some example of it? I tried here the option to Match entire cell contents, it worked.
Have you tried clean/trim this column before the replace ?
You are right.
I didn't realize the the strings have trailing spaces. That's why "Match entire cell contents" did not match anything.
From the point of view of the code, I insist that the documentation about Replacer.ReplaceValue (https://docs.microsoft.com/en-us/powerquery-m/replacer-functions) is not clear at all.
Regards
One way would be to add a Suffix like "#" to your column on the transform tab, then replace Capital Fed#. When you are done you can simply replace # with null (leave the replace field empty).
If this solution works for you, please mark it as the solution. Kudos are appreciated too. Please let me know if not.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
27 | |
12 | |
11 | |
11 | |
8 |
User | Count |
---|---|
54 | |
28 | |
15 | |
14 | |
13 |