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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
DanFromMontreal
Helper III
Helper III

Change ColumnType via table

Hello Dear Community,

I'm having trouble with the type automatically assigned by the Power Query Editor (PQE) so I want to force a type depending of the HeaderName.

When it sees the HeaderName in the table below, I want my code to force the type next to it.

When the HeaderName not in the table, I would like the PQE to return its best guess (not necessarely "type any")

I've looked into thew Table.TransformColumnType, which I'm sure it's the way to go but cannot figure it out.

Help needed.

Many thanks.

 

DanFromMontreal_0-1652969185802.png

 

2 REPLIES 2
watkinnc
Super User
Super User

I would first have power query take the best guess, by setting Automatically detect column types. After that, you do

 

Table.TransformColumnTypes(PriorStepOrTableName, List.Zip({tblType[HeaderName], tblType[Type]})

 

You may need to throw some quotes around the HeaderNames, I'm not sure because I'm not at my desk, but the point is to create the list of lists accepted by the function, like {{"HeaderName", type text}, {"AnotherHeader", type number}}

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

@watkinnc , it does not work.  Tried with some quotes with the same result.

It is providing me an error.

Any ideas how to modify the code to make it work?

I know that I'm using the code to replace the ColumnHeader and it is working fine.  It seems very similar...

#"Replace Cols Names" = Table.TransformColumnNames(#"Promote Header", each Text.Combine(List.ReplaceMatchingItems({_},List.Buffer(List.Zip({tblBeforeAfter[Before],tblBeforeAfter[After]})), Comparer.OrdinalIgnoreCase))),

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors