Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.