Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Power Query - Change Type from a range os columns by position

Hello everyone!

 

I´m trying to develop a personalized step to change the type of some columns in my table on Power Query that have the following structure (Table below).
However, this code will be an tool that will be apply to another data that can create more columns at the right of the table. So, in a future work, the number of columns can increase.

 

I would like to change the type from the "Column 3" until the end of the table. How can I code some step that can do that even that the numbers of columns increase?

 

The column 1 and column 2 must not change their type values.

Column 1Column 2Column 3Column 4Column 5Column 6Column 7
Name 1Name 16.803.696.652.541.98
Name 2Name 20.691.220.800.720.11
Name 3Name 36.449.521.767.791.17
Name 4Name 42.563.030.483.730.58

 

Thanks for any help.

  • ImkeF's avatar
    ImkeF
    7 years ago

    The function is also very simple, as it takes just one parameter (a table) as it's input. So you would adjust your query to this:

     

    let
        Source = Table.Combine({#"fUsage-Peak (REF)", #"fUsage_Off-Peak (REF)", #"fCIP (REF)", #"fTotal Cost (REF)", #"fExcedente Energia Reativa P (REF)", #"fExcedente Energia Reativa FP (REF)", #"fDemand Contracted Off-Peak (VERDE) (REF)", #"fDemand Registered Peak (Actual Null) (REF)", #"fDemand Contracted Peak (VERDE) (REF)", #"fDemand Registered Off Peak (Actual Null) (REF)", #"fDemand Registered Peak (Dem Peak) (REF)", #"fDemand Registered Off Peak (Dem Peak) (REF)", #"fDemanda Contracted Peak (AZUL) (REF)", #"fDemanda Contracted Off Peak (AZUL) (REF)", #"fReactive Demand Peak (REF)", #"fReactive Demand Off Peak (REF)"}),
        ApplyFunction = FunctionName(Source)
    in ApplyFunction

    Where "FunctionName" is the name of the query that holds the function code that you have copied.

     

    Please see attached file.

6 Replies