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.
A little tricky Subject Headline... Since im quite new to the Power BI game. I'd like to know if there is a way to rename contents of for example column "b" if a certain content in column "a" exists. Somehow i dont find a fitting solution with the Query Editor.
Solved! Go to Solution.
Yes, Table.Replace value is used for this. An example below
=Table.ReplaceValue(#"Changed Type",each [b],each if [a] ="abc" then "x" else [b],Replacer.ReplaceValue,{"b"})
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKk8tUtJRKihQitWJVkpMSgZyCgvBnPKSysoSILeoCEmuuFgpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [a = _t, b = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"a", type text}, {"b", type text}}),
Custom1 = Table.ReplaceValue(#"Changed Type",each [b],each if [a] ="abc" then "x" else [b],Replacer.ReplaceValue,{"b"})
in
Custom1
Yes, Table.Replace value is used for this. An example below
=Table.ReplaceValue(#"Changed Type",each [b],each if [a] ="abc" then "x" else [b],Replacer.ReplaceValue,{"b"})
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKk8tUtJRKihQitWJVkpMSgZyCgvBnPKSysoSILeoCEmuuFgpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [a = _t, b = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"a", type text}, {"b", type text}}),
Custom1 = Table.ReplaceValue(#"Changed Type",each [b],each if [a] ="abc" then "x" else [b],Replacer.ReplaceValue,{"b"})
in
Custom1
You can do it but you have to get into the Advanced Editor.
This code provides an example of one way to do this:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRMlSK1YlWSklNA7KNwOz0jEwg2xjMzsrOAbJNlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [a = _t, b = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"a", type text}, {"b", Int64.Type}}),
#"Look for in col A" = "ghi",
#"Conditional Rename" = if List.Contains(#"Changed Type"[a],#"Look for in col A")
then Table.RenameColumns(#"Changed Type",{"b","New Col Name"})
else #"Changed Type"
in
#"Conditional Rename"
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.