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
GregBeaumont
Advocate II
Advocate II

A Simple Method to Filter Text Strings in Query Editor

Using M in Query Editor, I'm looking for a simple and efficient means by which to remove non-letters from a text column in a table. For example, if the first two rows within a column have values "this is not all_text!" and "1234Letters$" I'd like them to become "this is not all text" and "Letters". A few entries also have emojis that are pulled into the query, and I'd also like to scrub those out. Any suggestions are appreciated!

1 ACCEPTED SOLUTION

No need to lowercase. Try this:

 

Text.Remove(..YourText.., List.Transform({0..64, 91..96, 123..50000}, each Character.FromNumber(_))))

 

This will remove every character within the range of 0..50000 that isn't a..z or A..Z. So if you have some special signs that you want to include, you need to find the number (Character.ToNumber) and include those numbers in the list above.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

7 REPLIES 7
ImkeF
Super User
Super User

I'm not aware of a "non-letter"-class in M.

Instead we have to define specificly a black- or whitelist: What shall stay in or what shall be removed?

Which route would you prefer?

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

I'm thinking I should set everything to lowercase, then create a whitelist for a-z. Probably the best way to eliminate odd characters. Thank you.

 

Greg B

No need to lowercase. Try this:

 

Text.Remove(..YourText.., List.Transform({0..64, 91..96, 123..50000}, each Character.FromNumber(_))))

 

This will remove every character within the range of 0..50000 that isn't a..z or A..Z. So if you have some special signs that you want to include, you need to find the number (Character.ToNumber) and include those numbers in the list above.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

pfuschi
Frequent Visitor

Hi Imke

This also removes characters written in non-latin alphabetics....

Any suggestions?

You need to find the corresponding numbers to these characters. Easiest might be to create a " translation-table", load it to excel and then search & Identify your ranges: Create a list: {1..50000}, convert to table and add a column: Character.FromNumber([ColumnName]).

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Brian_M
Responsive Resident
Responsive Resident

 

Nice!

Greg_Deckler
Super User
Super User

Well, Text.Remove provides a nice way of removing a list of characters but Text.Replace does not provide the functionality.

 

https://msdn.microsoft.com/en-us/library/mt260472.aspx

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.