Forum Discussion

GRANTWH's avatar
GRANTWH
Frequent Visitor
6 years ago

Compare 2 Columns in different Tables

Dear All,

 

I have 2 tables and want to compare two columns (one from each) in query editor. I just need a yes they (the text values) match (Protected) or no (Not protected) in a new column. I cobbled together the following, which doesn't work...

 

Compare Column = Table.AddColumn(#"Merged Columns", "Protection", each if (Trade Mark Portfolio [TM Compare]) = (Product List [Product Compare]) then "Protected" else "Not Protected"))

 

Many, many thanks in advance

Grant

4 Replies

  • What is your merge criteria? Do you have an index column in each of the tables?

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    If you don't have additional data transformations after this step, it would be easier to do this kind of comparison in a DAX calculated column.  So I suggest your load the tables and compare the values with LOOKUPVALUE() or some other way.

     

    If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat

    • GRANTWH's avatar
      GRANTWH
      Frequent Visitor

      Hi,

      I have 2 tables

      Table A

      Unique ID      Column 1     Column 2     Column 3

      1                       abc                  once           France

      2                       def                   twice          Germany

      3                       ghi                   three           US

      4                       abc                  twice           Germany

      5                       ghi                    five             UK

       

      Table B

      Unique ID     Column 1     Column 2     Column 3

      1                   fafa               1                    France

      2                   agsasg          3                    UK

      3                   agas              7                    US

      4                   afsf               3                    Germany

      5                   agag             5                    UK

       

      I want a new column to be created (in either table) that shows when the column 3 values in rows from each table match, as below:-

      New Table B

      Unique ID     Column 1     Column 2     Column 3     Column 4

      1                   fafa               1                    France          Match

      2                   agsasg          3                    UK                No Match

      3                   agas              7                    US                No Match

      4                   afsf               3                    Germany       Match

      5                   agag             5                    UK                Match

       

      Many many thanks in advance

      Grant

  • dax's avatar
    dax
    Community Support

    Hi GRANTWH , 

    As mentioned above, you could try to use Merge or use DAX to compare two columns. If possible could you please inform me more detailed information(such as your expected output and your sample data )? Then I will help you more correctly.

    Please do mask sensitive data before uploading.

    Thanks for your understanding and support.
    Best Regards,
    Zoe Zhi

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.