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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Mic1979
Helper V
Helper V

Change column type to percentage

Hello all,

 

I would like have a custom function able to change column type to percentage only if the column header has "%" inside.

 

I know the function to use is Table.TransformColumnTypes. I made this:

 

Changed_Type1 = Table.TransformColumnTypes(
     Table_to_Change,
          {{ List.Select (Table.ColumnNames (Table_to_Change), each Text.Contains (_, "%"),

              Percentage.Type}})

 

The point is that List.Select (Table.ColumnNames (Table_to_Change), each Text.Contains (_, "%") return a list, while there I need to have text.

 

How to do this?

 

Thanks.

 

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

Changed_Type1 = Table.TransformColumnTypes(
    Table_to_Change, 
    List.Transform(List.Select(Table.ColumnNames(Table_to_Change), each Text.Contains(_, "%")), each {_, Percentage.Type})
)

View solution in original post

2 REPLIES 2
AlienSx
Super User
Super User

Changed_Type1 = Table.TransformColumnTypes(
    Table_to_Change, 
    List.Transform(List.Select(Table.ColumnNames(Table_to_Change), each Text.Contains(_, "%")), each {_, Percentage.Type})
)

Thanks AlienSx

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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