Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hello,
I need to replace values in power query based on a condition:
If Column B contains 31456 or 42987 or 45028 change Column A to "Direct sales" otherwise leave column A as is. I've tried every example of code I can find on here and none work.
Solved! Go to Solution.
Hi @amay,
if you want to actually replace rather then add column and then delete/rename (which I think just as equally Ok performance-wise), you can try this code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LcfLFYAgDATAXvbMARJQOPq3h7z034a6Zm5jhgUJWmqb4Mmwvqsy+sxt31qWzu2xwR3/NHNnrHBXTLg7pnB/AA==", 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}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [B], "Direct Sales", (x, y, z)=> if List.Contains({31456, 42987, 45028}, y) then z else x,{"A"})
in
#"Replaced Value"
Cheers,
John
Hi @amay,
if you want to actually replace rather then add column and then delete/rename (which I think just as equally Ok performance-wise), you can try this code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LcfLFYAgDATAXvbMARJQOPq3h7z034a6Zm5jhgUJWmqb4Mmwvqsy+sxt31qWzu2xwR3/NHNnrHBXTLg7pnB/AA==", 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}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type",each [B], "Direct Sales", (x, y, z)=> if List.Contains({31456, 42987, 45028}, y) then z else x,{"A"})
in
#"Replaced Value"
Cheers,
John
you can try this. add a conditional column
refer two pics.
If I answered your question, please accept it as solution and give kudos.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
14 | |
13 | |
13 | |
12 | |
12 |