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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Replace Values based off two other columns OR and AND

Hello.  I am having some issues replacing a numeric value based off 2 other columns:

 

= Table.ReplaceValue(#"Removed Columns",each [UPC Code],
each if [Distributor AB No]=2224625 or [Distributor AB No]=2225152 or [Distributor AB No]=2225418 and [UPC Code]=8066095774 then 8066095721 else [UPC Code],
Replacer.ReplaceValue,{"UPC Code"})

 

It should only replace the UPC Code to (8066095721) if it is equal to the "Distributor AB No" and UPC = 8066095774.  However it is replacing other records with 8066095721.  Any ideas and thank you.

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

The issue is that and condition is coupled with last or condition. You need to put bracket around your all or condition so that they are treated as one. Hence, following would work

= Table.ReplaceValue(#"Removed Columns",each [UPC Code],
each if ([Distributor AB No]=2224625 or [Distributor AB No]=2225152 or [Distributor AB No]=2225418) and [UPC Code]=8066095774 then 8066095721 else [UPC Code],
Replacer.ReplaceValue,{"UPC Code"})

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you very much.  This has helped me greatly!

Vijay_A_Verma
Super User
Super User

The issue is that and condition is coupled with last or condition. You need to put bracket around your all or condition so that they are treated as one. Hence, following would work

= Table.ReplaceValue(#"Removed Columns",each [UPC Code],
each if ([Distributor AB No]=2224625 or [Distributor AB No]=2225152 or [Distributor AB No]=2225418) and [UPC Code]=8066095774 then 8066095721 else [UPC Code],
Replacer.ReplaceValue,{"UPC Code"})

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.