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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
McJasem
Frequent Visitor

Change Type to number - all but not first two Columns in my Column Names list.

Hi Guys

 

Isn't there a nifty way to tranform all but two columns in a list to a certain type - Number?

 

My Table.ColumnNames list only has 12 columns but it canfluctuate, and they are all of the data type Number, but the two first columns in the list. therefore i'd like the transformation to change all but the first two columns and not having to take count of how many columns there are in the list.

1 ACCEPTED SOLUTION
Jakinta
Solution Sage
Solution Sage

You can try with this step.

= Table.TransformColumnTypes( PriorStepName, List.Transform ( List.RemoveFirstN ( Table.ColumnNames(PriorStepName),2 ) , each {_, type number} ) )

View solution in original post

7 REPLIES 7
McJasem
Frequent Visitor

What if I have a dynamic shortened list of all the columns in the table. All but two of those columns in this list should change type to number. how can i reference this list of columns (skip 2) and change those column types to number out of all the table columns?

mahoneypat
Employee
Employee

Please use this expression to do that.  Replace Source with your actual previous step name.

 

= Table.TransformColumnTypes(Source, List.Zip({List.RemoveFirstN(Table.ColumnNames(Source), 2), List.Repeat({type number}, List.Count(List.RemoveFirstN(Table.ColumnNames(Source), 2)))}))

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi, do you have the same code but instead of changing type, I need to replace the values.

Hi @mahoneypat 

 

Thanks for the advice, i tried using the expression and it worked, but my needs changed slightly, and i found a work around in this expression:

= Table.TransformColumnTypes(#"Source", List.Transform (List.RemoveFirstN(List.RemoveLastN(Table.ColumnNames(#"Source"),2),3), each {_, type number}))

 

This way i have skiped changing type in the three first Columns as well as the two last Columns.

 

Just wanted to share my workaround!😊

Jakinta
Solution Sage
Solution Sage

You can try with this step.

= Table.TransformColumnTypes( PriorStepName, List.Transform ( List.RemoveFirstN ( Table.ColumnNames(PriorStepName),2 ) , each {_, type number} ) )

Thanks @Jakinta

 

It worked like a charm👌

 

 

StefanoGrimaldi
Resident Rockstar
Resident Rockstar

ummm, if you run an autodetect step it should assign all columns as number if they are indeed only number, and them set the 2 columns you want to be a different type to that certain type you want, like this those two named column will change to that type and al other column will get number format if they do have umber in them of course. 

if this helped give some kudos, if this solved yout quesiton please mark as solution for others to find it.





Did I answer your question? Mark my post as a solution! / Did it help? Give some Kudos!

Proud to be a Super User!




Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors