The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello,
I have the following table loaded in Power Query which is updated every week with new or removed or renamed columns in the source Excel spreadsheet. I am trying to find a dynamic way to change the Data Type of all the columns so that it will always be "Whole Number" without having to do this manually. The problem is that when it is autodetected, the data type is sometimes set to decimal. Can this be solved automatically?
Year | Week number | Stock | Returns | Defective |
2022 | 1 | 3 | 4 | 8 |
2022 | 2 | 6 | 9 | 17 |
2022 | 3 | 2 | 5 | 10 |
2022 | 4 | 9 | 3 | 16 |
2022 | 5 | 5 | 6 | 15 |
2023 | 6 | 2 | 2 | 10 |
2022 | 7 | 7 | 8 | 22 |
2022 | 8 | 3 | 3 | 13 |
2022 | 9 | 6 | 3 | 18 |
2022 | 10 | 3 | 3 | 14 |
2022 | 11 | 2 | 7 | 17 |
2022 | 12 | 3 | 7 | 22 |
2022 | 13 | 7 | 5 | 19 |
2022 | 14 | 9 | 8 | 18 |
2022 | 15 | 6 | 7 | 16 |
2022 | 16 | 7 | 14 | 34 |
Solved! Go to Solution.
Doing this manually generates M code that looks like
= Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Week number", Int64.Type}, {"Stock", Int64.Type}, {"Returns", Int64.Type}, {"Defective", Int64.Type}})
We can make this dynamic by transforming the list of column names into a list of {"ColumName", Int64.Type}.
= Table.TransformColumnTypes(Source, List.Transform(Table.ColumnNames(Source), each {_, Int64.Type}))
This should work for any number of integer columns.
Doing this manually generates M code that looks like
= Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Week number", Int64.Type}, {"Stock", Int64.Type}, {"Returns", Int64.Type}, {"Defective", Int64.Type}})
We can make this dynamic by transforming the list of column names into a list of {"ColumName", Int64.Type}.
= Table.TransformColumnTypes(Source, List.Transform(Table.ColumnNames(Source), each {_, Int64.Type}))
This should work for any number of integer columns.