This is best Fabric, Power BI, SQL and AI community event. How do we know? The last event sold out! Save €200 with code FABCMTY200.
Register nowA new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.
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.
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 4 | |
| 3 | |
| 2 | |
| 1 | |
| 1 |
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 6 | |
| 6 | |
| 4 |