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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Marcia_Ribeiro
Regular Visitor

To remove letters

Hello,
Please I would like some help.
I have this database here, and in the "Cód.Serviço" column there are numeric codes, codes with letters and numbers and codes with letters/numbers/letters again, as below, and I would like where there is a letter/number/letter to remove only the last letters, for example: from S14.01MCV to S14.01, from S14.01J to S14.01, how could I do that?

 

Base_Servico.png

 

Thanks,
Marcia.

2 ACCEPTED SOLUTIONS
jgeddes
Super User
Super User

One method would be to find the position of the first letter in the string that is not in the first position and then use that value to extract the string from the start to the determined value. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjE1U4rViVYKNjUzgjDMTM1MHNPcwBxHU5NkMMPI0MzUBMwCylqYJJUpxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Added Custom" = Table.AddColumn(Source, "TextLocations", each List.Min(List.RemoveItems(Text.PositionOfAny([Column1], {"a".."z", "A".."Z"}, Occurrence.All), {0}))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "NewColumn", each try Text.Start([Column1], [TextLocations]) otherwise [Column1])
in
    #"Added Custom1"

The code above walks through the steps. 

Hope this helps.




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

Proud to be a Super User!





View solution in original post

v-xinruzhu-msft
Community Support
Community Support

Hi @Marcia_Ribeiro 

You can try the following code.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjY00TMw9HUOU4rVgfG8lGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Start([Column1],List.Max(Text.PositionOfAny([Column1],{"0".."9"},Occurrence.All))+1))
in
    #"Added Custom"

Output

vxinruzhumsft_0-1708495466718.png

Best Regards!

Yolo Zhu

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

2 REPLIES 2
v-xinruzhu-msft
Community Support
Community Support

Hi @Marcia_Ribeiro 

You can try the following code.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjY00TMw9HUOU4rVgfG8lGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Start([Column1],List.Max(Text.PositionOfAny([Column1],{"0".."9"},Occurrence.All))+1))
in
    #"Added Custom"

Output

vxinruzhumsft_0-1708495466718.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

jgeddes
Super User
Super User

One method would be to find the position of the first letter in the string that is not in the first position and then use that value to extract the string from the start to the determined value. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNjE1U4rViVYKNjUzgjDMTM1MHNPcwBxHU5NkMMPI0MzUBMwCylqYJJUpxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Added Custom" = Table.AddColumn(Source, "TextLocations", each List.Min(List.RemoveItems(Text.PositionOfAny([Column1], {"a".."z", "A".."Z"}, Occurrence.All), {0}))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "NewColumn", each try Text.Start([Column1], [TextLocations]) otherwise [Column1])
in
    #"Added Custom1"

The code above walks through the steps. 

Hope this helps.




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

Proud to be a Super User!





Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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

Top Solution Authors