Forum Discussion
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 1 | Column 2 | Column 3 | Column 4 | Column 5 | Column 6 | Column 7 |
| Name 1 | Name 1 | 6.80 | 3.69 | 6.65 | 2.54 | 1.98 |
| Name 2 | Name 2 | 0.69 | 1.22 | 0.80 | 0.72 | 0.11 |
| Name 3 | Name 3 | 6.44 | 9.52 | 1.76 | 7.79 | 1.17 |
| Name 4 | Name 4 | 2.56 | 3.03 | 0.48 | 3.73 | 0.58 |
Thanks for any help.
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 ApplyFunctionWhere "FunctionName" is the name of the query that holds the function code that you have copied.
Please see attached file.
6 Replies
- ImkeFCommunity Champion
This function automatically transforms each column to the type of the value it finds in the first row: https://www.thebiccountant.com/2017/08/10/table-transform-column-types-to-first-rows-types/
Please check if it works for you.
- AnonymousNot applicable
Sorry, but I couldn´t use the function because I don´t know how to use the reference of the "(Table)=>" above the code.
I tried to modify the code, but it didn´t work out.
Can you tell me more about how to use this function using a simple example?
Thank you!
- ImkeFCommunity ChampionPlease watch this video where you can see how to use custom functions in Power Query: https://www.youtube.com/watch?v=6TQN6KPG74Q