Forum Discussion

webportal's avatar
webportal
Icon for Impactful Individual rankImpactful Individual
6 years ago

Check if value in column B exists in column A

Using Power Query, I need to check for each row of MyTable if the value in column B exists in column A.

If it does, then that value should be returned, then an empy field.

This is the code I'm trying to enter into an if statement somehow:

Table.Contains(MyTable,[B],[A])

Which is returing a cyclical reference error.

5 Replies

  • artemus's avatar
    artemus
    Icon for Microsoft Employee rankMicrosoft Employee

    Assuming this is in AddColumns...

     

    Just use:

    if Text.Contains([A], [B]) then
        [B]
    else
       null
    • webportal's avatar
      webportal
      Icon for Impactful Individual rankImpactful Individual

      Hi artemus 

      thanks, it always returns B (since B is a substring of A).

      I need to make an exact comparison, is there a function for that?

      • artemus's avatar
        artemus
        Icon for Microsoft Employee rankMicrosoft Employee

        Oh, just use:

        if [A] = [B] then
            [A]
        else
            null