Forum Discussion
Power Query - Change Type from a range os columns by position
- 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 ApplyFunctionWhere "FunctionName" is the name of the query that holds the function code that you have copied.
Please see attached file.
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.
- Anonymous7 years agoNot 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!
- ImkeF7 years agoCommunity ChampionPlease watch this video where you can see how to use custom functions in Power Query: https://www.youtube.com/watch?v=6TQN6KPG74Q
- Anonymous7 years agoNot applicable
Unfortunally, I still don´t get it how to use the code. Look, my table so far have the following columns. The columns 1 to 6 always will be in that order. However, from column 7 to final the number of columns can change depending of data range I´ll use.
I would like to set the type from column 7 until the end to "Decimal type". I´m trying to use the code that you´ve sent to me, but I´m still having problem with the first part (red circle on image written "Table").
My code it´s simple because this table it´s an append of others. This is the code.
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)"}) in Source