Forum Discussion
andyly85
2 years agoFrequent Visitor
Help with coding conditional functions in power query
Hello, How do I code this in Power Query please? If column 'Investment Vehicle Type' is Frontier Markets AND column Entity Relationship Name is 'TRP Fund of Funds', then Entity Relationship ...
- Anonymous2 years ago
Hi andyly85 ,
I can give you two ways:
First solution:#"Replaced Value" = Table.ReplaceValue( #"Changed Type", each if [Investment Vehicle Type] = "Frontier Markets" and [Entity Relationship Name] = "TRP Fund of Funds" then [Entity Relationship Name] else false, "Retirement Plan", Replacer.ReplaceValue, {"Entity Relationship Name"} )Origin:
Output:
Second solution:Custom1 = Table.FromRecords(Table.TransformRows(#"Changed Type",(x) => Record.TransformFields(x,{"Entity Relationship Name", each if x[Investment Vehicle Type] = "Frontier Markets" and x[Entity Relationship Name] = "TRP Fund of Funds" then "Retirement Plan" else _})))Origin:
Output:
Here are the two whole M codes in the Advanced Editor:
First one:let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcivKzyvJTC1S8E0syk4tKVbSUQoJClBwK81LUchPA9PFSrE6WBXml2SkFoElISwsWg1x6cVuCcwcqMmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Investment Vehicle Type" = _t, #"Entity Relationship Name" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Investment Vehicle Type", type text}, {"Entity Relationship Name", type text}}), #"Replaced Value" = Table.ReplaceValue( #"Changed Type", each if [Investment Vehicle Type] = "Frontier Markets" and [Entity Relationship Name] = "TRP Fund of Funds" then [Entity Relationship Name] else false, "Retirement Plan", Replacer.ReplaceValue, {"Entity Relationship Name"} ) in #"Replaced Value"Second one:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcivKzyvJTC1S8E0syk4tKVbSUQoJClBwK81LUchPA9PFSrE6WBXml2SkFoElISwStGJRGAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Investment Vehicle Type" = _t, #"Entity Relationship Name" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Investment Vehicle Type", type text}, {"Entity Relationship Name", type text}}), Custom1 = Table.FromRecords(Table.TransformRows(#"Changed Type",(x) => Record.TransformFields(x,{"Entity Relationship Name", each if x[Investment Vehicle Type] = "Frontier Markets" and x[Entity Relationship Name] = "TRP Fund of Funds" then "Retirement Plan" else _}))) in Custom1
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
2 years agoNot applicable
Hi andyly85 ,
I can give you two ways:
First solution:
#"Replaced Value" = Table.ReplaceValue(
#"Changed Type",
each if [Investment Vehicle Type] = "Frontier Markets" and [Entity Relationship Name] = "TRP Fund of Funds" then [Entity Relationship Name] else false,
"Retirement Plan",
Replacer.ReplaceValue,
{"Entity Relationship Name"}
)
Origin:
Output:
Second solution:
Custom1 = Table.FromRecords(Table.TransformRows(#"Changed Type",(x) => Record.TransformFields(x,{"Entity Relationship Name", each if x[Investment Vehicle Type] = "Frontier Markets" and x[Entity Relationship Name] = "TRP Fund of Funds" then "Retirement Plan" else _})))
Origin:
Output:
Here are the two whole M codes in the Advanced Editor:
First one:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcivKzyvJTC1S8E0syk4tKVbSUQoJClBwK81LUchPA9PFSrE6WBXml2SkFoElISwsWg1x6cVuCcwcqMmxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Investment Vehicle Type" = _t, #"Entity Relationship Name" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Investment Vehicle Type", type text}, {"Entity Relationship Name", type text}}),
#"Replaced Value" = Table.ReplaceValue(
#"Changed Type",
each if [Investment Vehicle Type] = "Frontier Markets" and [Entity Relationship Name] = "TRP Fund of Funds" then [Entity Relationship Name] else false,
"Retirement Plan",
Replacer.ReplaceValue,
{"Entity Relationship Name"}
)
in
#"Replaced Value"
Second one:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcivKzyvJTC1S8E0syk4tKVbSUQoJClBwK81LUchPA9PFSrE6WBXml2SkFoElISwStGJRGAsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Investment Vehicle Type" = _t, #"Entity Relationship Name" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Investment Vehicle Type", type text}, {"Entity Relationship Name", type text}}),
Custom1 = Table.FromRecords(Table.TransformRows(#"Changed Type",(x) => Record.TransformFields(x,{"Entity Relationship Name", each if x[Investment Vehicle Type] = "Frontier Markets" and x[Entity Relationship Name] = "TRP Fund of Funds" then "Retirement Plan" else _})))
in
Custom1
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.