Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I have a query template that returns results from sources wich can differ in the number and names of the columns. For example,, the columns may be thus:
time
value.1.a
value.1.b
value.2.a
value.2.b
value.3.on
...
The results always return a column named 'time' that I can easily convert to a Date/Time data type. The query results always produce some quantity of values with the 'a', 'b' or 'on' suffix, but the number and prefix names can vary. I am looking for a method to change the data type of all the columns with the 'a' or 'b' suffix to a decimal number and the columns with the 'on' suffix to a True/False (boolean) type.
Is there a method to select the columns by their suffix and then apply a transformation based on the selection?
Solved! Go to Solution.
Not entirely foolproof, but more checking can be added if necessary:
#"Changed Type" = Table.TransformColumnTypes(Source,
List.Transform(Table.ColumnNames(Source), each
let
split = Text.Split(_,"."),
types = if _ = "time" then type time
else if List.Last(split) = "a" then type number
else if List.Last(split) = "b" then type number
else if List.Last(split) = "on" then type logical else type any
in
{_, types}))
Not entirely foolproof, but more checking can be added if necessary:
#"Changed Type" = Table.TransformColumnTypes(Source,
List.Transform(Table.ColumnNames(Source), each
let
split = Text.Split(_,"."),
types = if _ = "time" then type time
else if List.Last(split) = "a" then type number
else if List.Last(split) = "b" then type number
else if List.Last(split) = "on" then type logical else type any
in
{_, types}))
Thank you...this worked exactly as expected for my query, and it allowed me to learn how to use a nested LET statement. The only tweak I made was my time column includes the date, so I changed the type to datetime.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.