Forum Discussion

M001's avatar
M001
Helper I
2 years ago
Solved

How to apply List for Dynamics Column Names in subsequence steps

Hi there,   My last 3 columns 2024, 2025 and 2026 always change from time to time, as it represents year of my sales that I want to track, therefore I created a list (I named it as Years) for these...
  • ronrsnfld's avatar
    2 years ago

    If it is only the last three columns that need to have dynamic names, you can set the data types for all the columns by creating a list similar to:

     

    #"Types List" = {{"Region", type text}, {"Country", type text}, {"Item", type text}, {"Price", Currency.Type}, {"Color", type text}}
        & List.Transform(List.LastN(Table.ColumnNames(#"Promoted Headers"),3), each {_, Int64.Type}),

     

    Then you can use it in the Transform.ColumnTypes function like:

     

        #"Promoted Headers" = ...,
        
    #"Types List" = {{"Region", type text}, {"Country", type text}, {"Item", type text}, {"Price", Currency.Type}, {"Color", type text}}
        & List.Transform(List.LastN(Table.ColumnNames(#"Promoted Headers"),3), each {_, Int64.Type}),
        
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers", #"Types List")
    in
        #"Changed Type"