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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
ragnezza
Frequent Visitor

List.Contains to Lookup for a value within the same table

Hello, I'm trying to come up with the M code to find if the value from one field is also in another field (equivalent of a VLOOKUP in Excel) within the same table. The table has two columns (A and B) and I want to create a third one (flag) that shows 'Yes' if the value in Column B is also in Column A.

 

Column AColumn Bflag
A01B01No
A02B01No
A03A01Yes
A04B01No
A05A02Yes

 

I added a Custom Column in Power Query with the following M code:

flag =
if  List.Contains( [Column A] , [Column B] ) then "Yes" else "No"

The 'flag' field creates but a bunch of 'Errors' show, and when I click on any error they show the following message:
Expression.Error: We cannot convert the value "A03" to type List.
Details:
Value=A03
Type=[Type]

 

Do I need to use a function to format either [Column A] or [ Column B] ? Or should I use a function different from List.Contains ?

Also, I cannot create this 'flag' in the front end with DAX (which would be much easier) because this 'flag' is already used as a key for a join within the Table M code.

 

Any suggestion will be greatly appreciated, thanks!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Write it like

 

if List.Contains(List.Buffer([PreviousStepName[Column B]), [Column A]) then "Yes" else "No"

 

--Nate

View solution in original post

2 REPLIES 2
ragnezza
Frequent Visitor

that's amazing, it's working.

 

Thanks!

Anonymous
Not applicable

Write it like

 

if List.Contains(List.Buffer([PreviousStepName[Column B]), [Column A]) then "Yes" else "No"

 

--Nate

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.