Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more
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
Solved! Go to 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}
)
)
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
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}
)
)
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.