There are a couple of useful actions that help a lot in cleaning data; removing digits, or keeping digits and removing everything else. In this short blog article, I’ll explain a simple method to do that using Power Query.
Sample Data
My sample data table looks like this:
Removing Digits
I can easily get rid of all digits wherever they are, using this action: adding a custom column:
Then the expression below (remember to use your column name instead of Column1 in the below expression):
Text.Remove(
[Column1],
{"0".."9"}
)
And here is the result;
Digits would be removed regardless of where they are in the text easily using the Text.Remove Power Query Function. And I used a list of digits from zero to nine to have all the range included.
Keeping Digits, Removing Everything Else
If you want to do the opposite of this action, after creating a custom column, you can use the code below;
This is, in fact, the opposite of previous action, it first finds all non digits (similar to the previous process), and then removes them to have only digits. and here is the result:
There are other methods to achieve the same results as well, however, these methods work simple and workable.
Reza Rad is a Microsoft Regional Director, an Author, Trainer, Speaker and Consultant. He has a BSc in Computer engineering; he has more than 20 years’ experience in data analysis, BI, databases, programming, and development mostly on Microsoft technologies. He is a Microsoft Data Platform MVP for 12 continuous years (from 2011 till now) for his dedication in Microsoft BI. Reza is an active blogger and co-founder of RADACAD. Reza is also co-founder and co-organizer of Difinity conference in New Zealand, Power BI Summit, and Data Insight Summit.
Reza is author of more than 14 books on Microsoft Business Intelligence, most of these books are published under Power BI category. Among these are books such as Power BI DAX Simplified, Pro Power BI Architecture, Power BI from Rookie to Rock Star, Power Query books series, Row-Level Security in Power BI and etc.
He is an International Speaker in Microsoft Ignite, Microsoft Business Applications Summit, Data Insight Summit, PASS Summit, SQL Saturday and SQL user groups. And He is a Microsoft Certified Trainer.
Reza’s passion is to help you find the best data solution, he is Data enthusiast.
His articles on different aspects of technologies, especially on MS BI, can be found on his blog: https://radacad.com/blog.
5 thoughts on “Remove Digits or Keep them in Power BI Using Power Query”
nicely done
@Reza – you can use something simpler to Select only Numbers and remove the text
=Text.Select([Column1],{“0”..”9″})
great one Sam. Haven’t worked with Text.Select before. looks great
Cheers
Reza
Hi, is there a way to let the “.” in the numbers?
sure you can. in the list of characters to keep, you can also add “.”
Cheers
Reza