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
Anonymous
Not applicable

Transforming character/number column

I have the column "Location" in my data model.  I need to separate it like this:

Column A: if Location starts with a number, I need all the numbers before the first letter

Column B: I need the first letter and each letter to follow before the next number

Column C: I need all the numbers after the last letter

 

An example below of correct results.

 

I would like to accomplish this in the Power Query Editor.  Any suggestions?

 

 

Capture1.PNG

1 ACCEPTED SOLUTION
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous,

 

I used a similar approach in the following post, https://community.powerbi.com/t5/Desktop/Replace-character-only-at-the-beginning-of-string-using-Power/m-p/465835#M216286, to help in a possible solution.

 

 

    // Converts the string into a list 
LocationToList = Table.AddColumn(#"Changed Type", "LocationToList", each Text.ToList([Location])), // Finds the Nth numbers in the beginning of the list
StartsWithNNums = Table.AddColumn(LocationToList, "StartsWithNNums", each List.FirstN([LocationToList], each Value.Is(Value.FromText(_), type number))), // Finds the Nth numbers at the end of the list
EndsWithNNums = Table.AddColumn(StartsWithNNums, "EndsWithNNums", each List.LastN([LocationToList], each Value.Is(Value.FromText(_), type number))), // Converts back into a string
ColumnA = Table.AddColumn(EndsWithNNums, "ColumnA", each Text.Combine([StartsWithNNums])), // Converts back into a string
ColumnC = Table.AddColumn(ColumnA, "ColumnC", each Text.Combine([EndsWithNNums])), // Uses @ImkeF solution
ColumnB = Table.AddColumn(ColumnC, "ColumnB", each Text.Remove([Location], List.Transform({48..57}, each Character.FromNumber(_)))) in ColumnB

 

@ImkeF solution that I modified for your needs found at https://community.powerbi.com/t5/Desktop/A-Simple-Method-to-Filter-Text-Strings-in-Query-Editor/td-p/87553.

 

Those add columns should return the the following for your sample:

 

7.PNG

 

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Anonymous,

 

Have you solved your problem with the solution from @ChrisMendoza?

 

If you have solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

If you still need help, please feel free to ask.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
ChrisMendoza
Resident Rockstar
Resident Rockstar

@Anonymous,

 

I used a similar approach in the following post, https://community.powerbi.com/t5/Desktop/Replace-character-only-at-the-beginning-of-string-using-Power/m-p/465835#M216286, to help in a possible solution.

 

 

    // Converts the string into a list 
LocationToList = Table.AddColumn(#"Changed Type", "LocationToList", each Text.ToList([Location])), // Finds the Nth numbers in the beginning of the list
StartsWithNNums = Table.AddColumn(LocationToList, "StartsWithNNums", each List.FirstN([LocationToList], each Value.Is(Value.FromText(_), type number))), // Finds the Nth numbers at the end of the list
EndsWithNNums = Table.AddColumn(StartsWithNNums, "EndsWithNNums", each List.LastN([LocationToList], each Value.Is(Value.FromText(_), type number))), // Converts back into a string
ColumnA = Table.AddColumn(EndsWithNNums, "ColumnA", each Text.Combine([StartsWithNNums])), // Converts back into a string
ColumnC = Table.AddColumn(ColumnA, "ColumnC", each Text.Combine([EndsWithNNums])), // Uses @ImkeF solution
ColumnB = Table.AddColumn(ColumnC, "ColumnB", each Text.Remove([Location], List.Transform({48..57}, each Character.FromNumber(_)))) in ColumnB

 

@ImkeF solution that I modified for your needs found at https://community.powerbi.com/t5/Desktop/A-Simple-Method-to-Filter-Text-Strings-in-Query-Editor/td-p/87553.

 

Those add columns should return the the following for your sample:

 

7.PNG

 

 

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



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.