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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Conditional formatting of a table based on header names

Hi

Does anyone have a bit of code that allows me to do something like this

if select table column header contains text "date" changed type "date".

Would be handy to stick this on the end of some of my queries rather than having to go through and select.

Regards

1 ACCEPTED SOLUTION

Think @Anonymous might mean something like this instead.

let
    [...],
    previousStepName = [...],
    dateCols = List.Select(Table.ColumnNames(previousStepName), each Text.Contains(Text.Lower(_), "date")),
    transformationsList = List.Transform(dateCols, each {_, type date}),
    autoDateType = Table.TransformColumnTypes(previousStepName, transformationsList)
in
    autoDateType

 

Or in one step:

autoDateType =
    Table.TransformColumnTypes(
        previousStepName,
        List.Transform(
            List.Select(
                Table.ColumnNames(previousStepName),
                each Text.Contains(Text.Lower(_), "date")
            ),
        each {_, type date}
        )
     )

View solution in original post

2 REPLIES 2
BA_Pete
Super User
Super User

Hi @Anonymous ,

 

I'm assuming you mean you want to be able to automatically perform functions on certain columns if they exist in the table.

 

Try this:

autoChangeTypes =
    if List.Contains(Table.ColumnNames(previousStepName), "columnToFindName")
    then Table.TransformColumnTypes(previousStepName,{{"columnToFindName", type text}})
    else previousStepName

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Think @Anonymous might mean something like this instead.

let
    [...],
    previousStepName = [...],
    dateCols = List.Select(Table.ColumnNames(previousStepName), each Text.Contains(Text.Lower(_), "date")),
    transformationsList = List.Transform(dateCols, each {_, type date}),
    autoDateType = Table.TransformColumnTypes(previousStepName, transformationsList)
in
    autoDateType

 

Or in one step:

autoDateType =
    Table.TransformColumnTypes(
        previousStepName,
        List.Transform(
            List.Select(
                Table.ColumnNames(previousStepName),
                each Text.Contains(Text.Lower(_), "date")
            ),
        each {_, type date}
        )
     )

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors