Forum

Filtering out numbe...
 
Notifications
Clear all

Filtering out numbers from a text based column

4 Posts
2 Users
0 Reactions
56 Views
(@ssmyth)
Posts: 2
New Member
Topic starter
 

I have a text column in PQ that contains both numbers and alpha-numerics.  I would like to be able to filter out the true numbers leaving the records that have the alpha-numeric values.  Has anyone run into this challenge before?  Any suggestions would be most appreciated.

 

Thanks S. Smyth

 
Posted : 16/12/2020 12:55 pm
(@mynda)
Posts: 4761
Member Admin
 

Hi Sonny,

The code below only removes letters from the string so you're left with numbers. Note: It doesn't remove special characters, and it assumes your data is in a table, but obviously you'd need to modify the code if your data is in a record or list.

let  
Source = 
Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JYwxCsAwDAP/kkfE6tixc8hQQgaBiR/g/0OjBoyMJZ3HKMsID14IYzokFhJ64D+q/J0inYsJq3u2t6gdOICemIpiKnFI3P3pbytzfg==", BinaryEncoding.Base64), Compression.Deflate)), 
let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [String = _t]),    
Res = Text.Combine(List.RemoveItems(List.RemoveItems(Text.ToList(Source[String]{0}),{"a" .. "z"}),{"A" .."Z"}),"") 

in    

Res

If you get stuck, please provide a sample file and we can help you further.

Mynda

 
Posted : 16/12/2020 6:59 pm
(@ssmyth)
Posts: 2
New Member
Topic starter
 

Mynda,

Thank you for your response.  Actually I have a different scenario.  My data is in a table and I would like to filter out all the rows that aren't numbers.  Example 789 vs D0001.  See Before and After below.

 

Before

123

456

D0001

CAT/ 499

789

 

After

123

456

789

 

Thank you,

Sonny

 
Posted : 17/12/2020 9:20 am
(@mynda)
Posts: 4761
Member Admin
 

Hi Sonny,

Oh, ok. That's easy. Change the data type for the column to whole or decimal number. Those values with text will return errors. You can simply filter out the errors.

Mynda

 
Posted : 18/12/2020 9:17 am
Share: