Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep only numbers in a string / remove all non-numbers

I have a string column where I only need to the numbers from each string, e.g.

A-123  -> 123
456    -> 456
7-X89  -> 789   

How can this be done in PowerQuery?

like image 551
Peter Albert Avatar asked Sep 15 '25 15:09

Peter Albert


1 Answers

Add column. In custom column formula type this one-liner:

= Text.Select( [Column], {"0".."9"} )

where [Column] is a string column with a mix of digits and other characters. It extracts numbers only. The new column is still a text column, so you have to change the type.


Edit. If there are dots and minus characters:

= Text.Select( [Column1], {"0".."9", "-", "."} ))

Alternatively, you can transform the existing column:

= Table.TransformColumns( #"PreviousStepName" , {{"Column", each Text.Select( _ , {"0".."9","-","."} ) }} )
like image 198
Przemyslaw Remin Avatar answered Sep 18 '25 10:09

Przemyslaw Remin