Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A 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.

Reply
Anonymous
Not applicable

Auto set all column types to specific Data Type

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?

 

YearWeek numberStockReturnsDefective
20221348
202226917
202232510
202249316
202255615
202362210
202277822
202283313
202296318
2022103314
2022112717
2022123722
2022137519
2022149818
2022156716
20221671434
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

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.

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

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.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.