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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
CrisYan
Resolver III
Resolver III

Replace character only at the end of string using Power Query (Regex $)

Hi! I need some help please :).


I want to replace two characters ONLY if are placed at the end of string of one column.

I'm using Power Query and the following Query to replace the " L" characters (notice the leading space).

= Table.ReplaceValue(#"Ant_Query"," L","",Replacer.ReplaceText,{"COLUMN_TO_APPLY"})

 

But the results are not what I need.

 

Desirable:

"TEST L" --> "TEST"
"TEST LONG" --> "TEST LONG"

"TEST LONG L" --> "TEST LONG"

Actual:

"TEST L" --> "TEST"
"TEST LONG" --> "TESTONG"
"TEST LONG L" --> "TESTONG"

 

Using the "( L)$" Regex to search and replace the value would do the trick.

 

TY very much for the help, and Regards!

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

You can use the following formula:

 

= Table.TransformColumns(
Ant_Query,
{{"COLUMN_TO_APPLY",
each if Text.EndsWith(_," L")
then Text.Start(_,Text.Length(_)-2)
else _,
type text}})
Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
MarcelBeug
Community Champion
Community Champion

You can use the following formula:

 

= Table.TransformColumns(
Ant_Query,
{{"COLUMN_TO_APPLY",
each if Text.EndsWith(_," L")
then Text.Start(_,Text.Length(_)-2)
else _,
type text}})
Specializing in Power Query Formula Language (M)

It works!, TY very much (:

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.