Power Query M code
let
Source = YourTable,
ChangedType = Table.TransformColumns(
Source,
{{"ColumnName", each try Int64.From(_) otherwise null, Int64.Type}}
)
in
ChangedType
Converts a column to Int64, replacing any value that fails to convert with null instead of erroring the whole query.
let
Source = YourTable,
ChangedType = Table.TransformColumns(
Source,
{{"ColumnName", each try Int64.From(_) otherwise null, Int64.Type}}
)
in
ChangedType
Use this instead of Table.TransformColumnTypes when the column may contain values that won't convert cleanly, like blanks or stray text.
Browse all 145 snippets in the Power Query M Code Snippets, or search the library for something similar to Convert a Column to Whole Number Safely.