Forum Discussion
Importing table with predefined data type from metadata
- 1 year ago
Solution code:
let types = [Text = Text.From, #"Decimal number" = Number.From, #"Whole number" = Int64.From], type_table = Table.Group( Excel.CurrentWorkbook(){[Name="ColumnDataTypes"]}[Content], "TableName", { "transform", (x) => List.Zip( { x[ColumnName], List.Transform(x[ColumnDataType], (w) => Record.FieldOrDefault(types, w, each _)) } ) } ), type_record = Function.Invoke(Record.FromList, List.Reverse(Table.ToColumns(type_table))), result = ((table_name) => Table.TransformColumns( Record.Field(#shared, table_name), Record.Field(type_record, table_name), null, MissingField.Ignore )) ("PetTable") in resultapproach taken from https://www.excelforum.com/office-365/1433993-power-query-to-import-column-data-types-from-table.html
Best,
Jacek
Thank you very much,
I went with the settings and I am ready to write power query M code to read metadata.
Best,
Jacek
Hi jaryszek,
Please create a function in Power Query to map data types and then using Table.TransformColumnTypes to manually assign the appropriate data types to your dataset for better control and accuracy.
Reference documents:
Using custom functions in Power Query - Power Query | Microsoft Learn
Table.TransformColumnTypes - PowerQuery M | Microsoft Learn
If you find this post helpful, please mark it as an "Accept as Solution" and consider giving a KUDOS. Feel free to reach out if you need further assistance.
Thanks and Regards