Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
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 February 2025 Power BI update to learn about new features.
User | Count |
---|---|
27 | |
27 | |
25 | |
13 | |
10 |
User | Count |
---|---|
24 | |
19 | |
16 | |
13 | |
10 |