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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
EimearC
Frequent Visitor

Help with "if column values do not match another column values then..."

Hi there,

I'm hoping someone can please assist me with this M code I am trying to impliment: 

 

I have a small table called TableCR which has 5 values:

 

1-EXCELLENT
2-GOOD
3-FAIR
4-POOR
5-UNSERVICEABLE

 

Then I have another main table called Audit. One of the columns within the Audit table is called Rating. What I am hoping for is that I can do a lookup from the Rating column to state that if any of the values within the Rating column does not equal any of the 5 values within the TableCR table, column called "RatingCheck" then I apply a default value,"3-FAIR", to the non matching value. 

If the values are within the other table, then leave as is. 

 

This is what I have currently but it's replacing every single value with "3-FAIR" instead of just the non matching values, can anyone please assist me to tweak this to get it to work as hoped? 

= Table.ReplaceValue(#"Replaced CRating", each [Rating], each if [Rating] <> TableCR[RatingCheck] then "3-FAIR" else [Rating], Replacer.ReplaceValue, {"Rating"} )

 

 Thank you so much for your time.

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @EimearC 

 

Download example PBIX file

 

Might be simpler to add a Custom Column

 

if not List.ContainsAny(TableCR[RatingCheck], {[Rating]}) then "3-FAIR" else [Rating]

 

rating.png

then delete the old rating column and rename the new column you just created.

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

2 REPLIES 2
EimearC
Frequent Visitor

Thanks so much @PhilipTreacy for the workaround. I will use that solution.

 

If anyone else does read this & might be able to solve why my original M Code is currently not working though I would love to understand why that is. 

PhilipTreacy
Super User
Super User

Hi @EimearC 

 

Download example PBIX file

 

Might be simpler to add a Custom Column

 

if not List.ContainsAny(TableCR[RatingCheck], {[Rating]}) then "3-FAIR" else [Rating]

 

rating.png

then delete the old rating column and rename the new column you just created.

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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