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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Mic1979
Post Patron
Post Patron

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

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

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

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