Forum Discussion
Setting a default data type
- 1 year ago
hi Dicken ,
To set a default data type dynamically in Power Query, use Table.TransformColumns with try...otherwise to apply a transformation to all columns:let Source = YourTable, SetDefaultType = Table.TransformColumns( Source, List.Transform( Table.ColumnNames(Source), each {_, each try Number.From(_) otherwise _, Int64.Type} ) ) in SetDefaultTypeThis applies Int64.Type to numeric columns while leaving others unchanged, avoiding manual column-by-column specification.
Actually it doesn't quite work, as the all end up as number, where I want the text columns as text
and number as Int64. so as transform type ; Table.TransformColumnTypes( Source,{ {"T", type text }, {"N", Int64.Type }} )
or a default as number
Table.TransformColumns( Source,{ {"T", Text.From}} , Number.From)
if not a default this works;
= Table.TransformColumns( Source, {"T", Text.From}, { "N", Number.From, Int64.Type }} )
But I have not been able to get it as a default option.
I shall persevere.
Richad.
Please define more clearly what you are trying to accomplish. "Default" is a subjective term.