cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dlopez
Advocate I
Advocate I

Replace entire column text value

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

1 ACCEPTED SOLUTION
camargos88
Super User III
Super User III

@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 ?

 

Capture.PNG



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

4 REPLIES 4
dax
Community Support
Community Support

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.

camargos88
Super User III
Super User III

@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 ?

 

Capture.PNG



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

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

mahoneypat
Super User IV
Super User IV

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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors
Top Kudoed Authors