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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kpathiakis
Frequent Visitor

Remove trailing 2 characters from end string

Hello,

 

I am rather new to the M langauge and need some help. 

 

I have a column with strings that are either BFD###### or BF###### . I am looking to remove the last 2 characters from this string, so each will either be BFD#### or BF####. I have tried other methods but I end up with only 1 character being removed from the BFD strings and zero characters being removed from the BF strings.

Thank you for your help

1 ACCEPTED SOLUTION

Hi @kpathiakis ,

Based on my test, you could refer to below steps:

In power query:

Add a custom column and enter below code:

Text.Start([Data],Text.Length([Data])-2)

Result:

1.PNG

In dax, you could refer to below formula:

Column = LEFT('Table1 (2)'[Data],LEN('Table1 (2)'[Data])-2)

Result:

2.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

If the end goal is to have each be 7 characters long, can use the following as a new column in Power Query:

Text.Start( 
[Column1],
7
)

Thanks for the help! In the end, it will be either 6 or 7 characters. I am basically looking to remove the 2 end characters, no matter how long the string is 

@kpathiakis 

 

This request looks like it may solve your issue if you haven't got it already.

 

https://community.powerbi.com/t5/Desktop/Power-Query-Remove-last-two-characters-from-a-column/td-p/3...

 

Scott

 

 

@slounsbury 

 

Thanks Scott. I actually had tried that. But what it is doing is either removing 1 or 2 characters. Take a look at the outcome when I try to split the columns. The left is the before, the right is the after.  ;

snip.JPG

Hi @kpathiakis ,

Based on my test, you could refer to below steps:

In power query:

Add a custom column and enter below code:

Text.Start([Data],Text.Length([Data])-2)

Result:

1.PNG

In dax, you could refer to below formula:

Column = LEFT('Table1 (2)'[Data],LEN('Table1 (2)'[Data])-2)

Result:

2.PNG

You could also download the pbix file to have a view.

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
slounsbury
Helper II
Helper II

Hi @kpathiakis 

 

One thing you could try is going into the Power Query Editor and split the column after 7 characters and then deleting the column it creates from the split which would leave you with the column you are looking for. You can always go through and remove the applied steps in the editor if you need to revert it or are not satisfied with the outcome.

 

Scott

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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