Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
andyly85
Frequent 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 Name is 'Retirement Plan'.  Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not 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:

vjunyantmsft_0-1728024960202.png

Output:

vjunyantmsft_1-1728025033672.png


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:

vjunyantmsft_2-1728025141478.png

Output:

vjunyantmsft_3-1728025151139.png


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.

View solution in original post

4 REPLIES 4
Anonymous
Not 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:

vjunyantmsft_0-1728024960202.png

Output:

vjunyantmsft_1-1728025033672.png


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:

vjunyantmsft_2-1728025141478.png

Output:

vjunyantmsft_3-1728025151139.png


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.

Omid_Motamedise
Super User
Super User

Use this formula


= Table.ReplaceValue(Source, each [Investment Vehicle Type]="Frontier Markets " and  [Entity Relationship Name]="TRP Fund of Funds" ,"",(a,b,c)=> if b then "Retirement Plan" else a ,{"Entity Relationship"})

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
audreygerred
Super User
Super User

Hi! Here is what I used in order to achieve the below:

audreygerred_0-1727799028403.png

#"Added Custom" = Table.AddColumn(#"Changed Type", "Entity Relationship NEW", each if [Invest Veh Type] = "Frontier Markets" and [Entity Relationship Name] = "TRP Fund of Funds" then "Retirement Plan" else [Entity Relationship Name])

 

Here is the entire M-Code I have:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcivKzyvJTC1S8E0syk4tKVbSUQoJClBwK81LUchPA9PFSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Invest Veh Type" = _t, #"Entity Relationship Name" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Invest Veh Type", type text}, {"Entity Relationship Name", type text}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Entity Relationship NEW", each if [Invest Veh Type] = "Frontier Markets" and [Entity Relationship Name] = "TRP Fund of Funds" then "Retirement Plan" else [Entity Relationship Name])
in
#"Added Custom"





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi!  Is it possible to code it without adding a new column?  Thanks!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.