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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Replace Value if any field is a certain value

I am attempting to find a good way to accomplish this find and replace.  Using the example data below, I would like to replace the "No" value in the intake column if any of the Ref IDs have "Yes" in the Intake Column.  

 

 

Ref IDCodeIntake
15375PR111751Yes
15375PR111772No
1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
you can:
1) Group on RefID and choose "All rows" for aggregation

2) Add a column that checks if "Yes" is included anywhere for the RefID

3) Expand all columns and add a column that checks for "Yes" and replaces if matching:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1NjdV0lEKCDI0NDQ3NQQyI1OLlWJ10KXMjYBMv3yl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Ref ID" = _t, Code = _t, Intake = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref ID", Int64.Type}, {"Code", type text}, {"Intake", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Ref ID"}, {{"All", each _, type table [Ref ID=nullable number, Code=nullable text, Intake=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "ContainsYes", each List.Contains([All][Intake], "Yes")),
    #"Expanded All" = Table.ExpandTableColumn(#"Added Custom", "All", {"Code", "Intake"}, {"Code", "Intake"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded All", "Custom", each if [ContainsYes] then "Yes" else [Intake]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Intake", "ContainsYes"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Intake"}})
in
    #"Renamed Columns"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

3 REPLIES 3
ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
yes, each _ basically returns the whole (partitioned) table.

Great to see it worked for you!

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
you can:
1) Group on RefID and choose "All rows" for aggregation

2) Add a column that checks if "Yes" is included anywhere for the RefID

3) Expand all columns and add a column that checks for "Yes" and replaces if matching:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQ1NjdV0lEKCDI0NDQ3NQQyI1OLlWJ10KXMjYBMv3yl2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Ref ID" = _t, Code = _t, Intake = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref ID", Int64.Type}, {"Code", type text}, {"Intake", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Ref ID"}, {{"All", each _, type table [Ref ID=nullable number, Code=nullable text, Intake=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "ContainsYes", each List.Contains([All][Intake], "Yes")),
    #"Expanded All" = Table.ExpandTableColumn(#"Added Custom", "All", {"Code", "Intake"}, {"Code", "Intake"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded All", "Custom", each if [ContainsYes] then "Yes" else [Intake]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Intake", "ContainsYes"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Intake"}})
in
    #"Renamed Columns"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Thanks @ImkeF !  I was hoping to avoid Grouping Rows since I have 20 other Columns of Data that I did not add to the example and I have had issues with losing columns in the past.  Is the each_ in the Grouped Rows function the reason I was able to expand and see all the columns again?  This did work great and I only received an error on the Added Custom1 step.  I used this instead:

#"Added Custom1" = Table.AddColumn(#"Expanded All", "Custom", each if [All.Intake] = "No" and [ContainsYes] = "FALSE" then "No" else "Yes"),

 Thanks again, Jared

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors