Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
DWJames
Regular Visitor

How to only Replace Values which end with a particular string? the equivalent of Regex $

Hi all,

I'm moving some time-consuming data conversion processes into power BI, but I've hit a wall that I previously used to use multiple regex commands to handle value replacement and don't know to achieve this in powerBI

 

If my data set is 

 

Red

Blue

Silver

Polished Sil

Matt Sil

 

I would like to change both instances of 'Sil' to be 'Silver' but NOT to include the record which is already 'Silver' 

 

In regex I would use Sil$ and this would catch only things which ended Sil. Is there an equivalent here?

 

Also, while I'm here, if I have around 50 of these replacements to apply each time, is there a simple way I can maintain a separate list of replacements and ask the replace values function to work through them in order rather than me stacking up a tonne of Table.ReplaceValue queries?

 

thanks,

James

 

 

1 ACCEPTED SOLUTION
v-sihou-msft
Microsoft Employee
Microsoft Employee

@DWJames

 

Please try DAX formula below;

 

Column = IF(RIGHT(Table1[Color],3)="Sil",
	REPLACE(Table1[Color],LEN(Table1[Color])-2,3,"Silver")
	,Table1[Color])

66.PNG

 

 

Regards,

View solution in original post

4 REPLIES 4
v-sihou-msft
Microsoft Employee
Microsoft Employee

@DWJames

 

Please try DAX formula below;

 

Column = IF(RIGHT(Table1[Color],3)="Sil",
	REPLACE(Table1[Color],LEN(Table1[Color])-2,3,"Silver")
	,Table1[Color])

66.PNG

 

 

Regards,

Thanks guys

 

dkay84_PowerBI
Microsoft Employee
Microsoft Employee

To offer another option, in the query editor, you could choose the Replace Value function and replace " Sil" with " Silver".  Notice the leading space in the value to replace which should distinguish these values from the correct values (as well as the leading space in the replaced value to keep the words separate).

parry2k
Super User
Super User

I believe you can achieve this by adding another column and DAX to achieve this, here is an example:

 

My New Field = IF(IFERROR(SEARCH("Sil", Table1[Yourcolumn]),-1) = -1, Table1[Yourcolumn], "Silver")  

I'm sure there are various way to do this but just want to share this one.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.