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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Simming2022
Frequent Visitor

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
Simming2022
Frequent Visitor

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors