Forum Discussion

Lucian's avatar
Lucian
Icon for Responsive Resident rankResponsive Resident
2 years ago
Solved

M formula to check if text is a number and avoid errors

Hello, I need for a table to test if the first 4 characters in a column are numeric, do something... else do something else.   For example, let's consider this single column table:   TestColumn ...
  • Lucian's avatar
    Lucian
    2 years ago

    Hi mlsx4 ,

     

    Thank you for your suggestion that could be a solution. My problem is that is not just a single if but multiple if inside if.

    Meanwhile it seems that I found the solution that initially I've missed out (forgot): TRY... OTHERWISE...

    So the following formula it seems it worked:

     

    = Table.AddColumn(#"Added Custom", "Custom2", each if (try Value.Is(Number.FromText(Text.Start([TestColumn],4)), Int64.Type) otherwise false) then "Is number" else "Not number", type text)

     

    And now it seems I've got the expected result:

     

     

    Kind Regads,

    Lucian