Forum Discussion

qasimawan's avatar
qasimawan
Frequent Visitor
4 years ago
Solved

Check if a value exists in another table

Hello Community!

 

I am relatively new M Langauge and I want to know how to check if the string exists in another column. I have used an Excel formula such as: isNumberMatch

 

I will elaborate on my question further to provide some context.

 

I have two queries:

 

Query 1 contains my source data which has every detail.

Query 2 is another table that contains data.

 

I have done a string concatenation in both queries, meaning, i have joined, FirstName, LastName and EmailAddress.

 

In query 2, I want to create a custom column which checks if the concatenated column in Query 2 matches the concatenation in Query 1. 

 

I have tried to do this but I don't know how to reference a column in another query:

if Table.SelectColumns(#"NHSP Data Edit","Concat") = Table.SelectColumns(#"Daily SiP - Edit","Concat") then "true" else "false"

 

Thanks for your help!

  • Hi qasimawan ,
    sorry, yes, the code has to be adjusted:
    if List.Contains(#"query1"[Concat], [Concat]) then "true" else "false"

3 Replies

  • ImkeF's avatar
    ImkeF
    Community Champion

    Hi qasimawan ,

    if my understanding is correct, you want to check if a certain value in each row of a table (query2) is contained anywhere in the whole column of table from query1.
    If so, you'd add a column in query2 like so:

    if List.Contains( Table.SelectColumns(#"query1","Concat"), [Concat]) then "true" else "false"

  • ImkeF's avatar
    ImkeF
    Community Champion

    Hi qasimawan ,
    sorry, yes, the code has to be adjusted:
    if List.Contains(#"query1"[Concat], [Concat]) then "true" else "false"

  • qasimawan's avatar
    qasimawan
    Frequent Visitor

    Hi Imkef, 

     

    Many thanks for your reply! 

     

    Unfortunately, I have ran into this error which I can't eliminate. I have added a change type step and manually changed the data types but the error hasn't gone away. 

     

    Here is the error message: Expression.Error: We cannot convert a value of type Table to type List.
    Details:
    Value=[Table]
    Type=[Type]