Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Auto set all column types to specific Data Type

Hello, I have the following table loaded in Power Query which is updated every week with new or removed or renamed columns in the source Excel spreadsheet. I am trying to find a dynamic way to chang...
  • AlexisOlson's avatar
    3 years ago

    Doing this manually generates M code that looks like

    = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Week number", Int64.Type}, {"Stock", Int64.Type}, {"Returns", Int64.Type}, {"Defective", Int64.Type}})

    We can make this dynamic by transforming the list of column names into a list of {"ColumName", Int64.Type}.

    = Table.TransformColumnTypes(Source, List.Transform(Table.ColumnNames(Source), each {_, Int64.Type}))

    This should work for any number of integer columns.