Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Mcode: Custom Column- Evaluate IF Text Column has Number Value

Hello,   I have a Text Column that has values 00 to 99 and AA to ZZ, how do I eveluate in M to check IF the column has number value?   IF it column is between the number range the Custom Column w...
  • Jimmy801's avatar
    5 years ago

    Hello Anonymous 

     

    you can add a custom column with this formula (you have to replace "Column1" with your real column name)

     

    if List.AllTrue(List.Transform(Text.ToList([Column1]), each try Value.Is(Number.From(_), type number) otherwise false)) then "numeric" else "alpha numeric"

     

    Here the complete code example

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjRUitWJVjI2BlNRUWDKACIIlXN2hshBeJaWECUGSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if List.AllTrue(List.Transform(Text.ToList([Column1]), each try Value.Is(Number.From(_), type number) otherwise false)) then "numeric" else "alpha numeric")
    in
        #"Added Custom"

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy