Forum Discussion

mahenkj2's avatar
mahenkj2
Icon for Solution Sage rankSolution Sage
2 years ago
Solved

Comparing two tables on multiple column resulting full match and partial match

Hi,

 

I am trying to find a solution for below scenario:

 

There are two table. 

Table-1     
IDNameInvoice NumberInvoice amountTax rateTax amount
AA0JohnAax/2359104005%520
AB0AlbertBbc/231520012%1824
AA0JohnCCd/231500018%2700
BB0StephyBFG/5422800018%5040

 

Table-2     
IDNameInvoice NumberInvoice amountTax rateTax amount
AA0John2359104005%520
AB0AlbertBbc/231520012%1824
AA0JohnCCd/23150005%750
CDFKelleyASG/542312005%60

 

Aim is to find the match in both the tables by comparing ID+Name+Invoice Number +Invoice Amount+Tax rate. If such combinations are matched in both the tables, it will be like 'full match'.

 

But if say for one entry, invoice number is wrong due to some reason, but still ID+Name+Invoice Amount+Tax rate are matching and invoice number is partially matching, we will term as 'partial match'.

 

It is also possible that, one table have some entry which is not present in another, then we term it as 'Not in Table-1' or 'Not in Table-2'.

 

I reproduce the expected output as well below:

 

Intended result             
 Table-1 dataTable-2 dataDifference
IDNameTable-1-Invoice numberTable-1-Invoice amountTable-1-Tax rateTable-1-Tax amountTable-2-Invoice NumberTable-2-Invoice amountTable-2-Tax rateTable-2-Tax amountResultInvoice numberInvoice amountTax rateTax amount
AA0JohnAax/2359104005%5202359104000.05520Partial matchMismatch   
AB0AlbertBbc/231520012%1824Bbc/231520012%1824Match    
AA0JohnCCd/231500018%2700CCd/23150005%750Partial match  MismatchMismatch
BB0StephyBFG/5422800018%5040    Not in Table-1    
CDFKelley    ASG/542312005%60Not in Table-2    

 

Similary it is possible that ID+Name+Invoice Number +Invoice Amount are matching for an entry in both the tables but tax rate is wrong/mismatch and we mark it as partial match for Tax rate mismatch.

 

So, it is kind of comparing multiple columns.

 

I have done much work on this problem in power query but multiple column comparison is a challenge for me so far.

 

Any help is much appreciated.

  • mahenkj2 ,

     

    The key to this issue is the usage of the Fuzzy Merge. This allow the Merge of the two tables by the fields ID, Name and Invoice Number but allowing a match of at least 80% (value by default but can be edited) and ignoring case and spaces.

     

     

    With this Fuzzy Merge with a Full Outer kind you can afterwards compare each combinations and also find if a record is only on one the tables:

     

     

    Final result:

     

     

    Here is a link with the PowerBI file used : https://we.tl/t-DDvMm0z6Wb

     

    Hope this answer solves your problem!
    If you need any additional help please @ me in your reply.
    If my reply provided you with a solution, please consider marking it as a solution โœ”๏ธ or giving it a kudo ๐Ÿ‘
    Thanks!

    You can also check out my LinkedIn!

    Best regards,
    Jorge Pessoa

4 Replies

  • jpessoa8's avatar
    jpessoa8
    Icon for Continued Contributor rankContinued Contributor

    Hi mahenkj2 ,

     

    I think I'll be able to create a solution in PowerQuery based on GroupBy's. The issue is, when you have partial matches, since you will only display 1 row, which criteria should be use to identify?

     

    Table1

    AA0JohnAax/2359104005%520

     

    Table2

    AA0John2359       104005%520

     

    The difference is on Invoice Number. Which one is going to be displayed?

    • mahenkj2's avatar
      mahenkj2
      Icon for Solution Sage rankSolution Sage

      Thanks.

      Since there is a partial match in invoice number, but other things are matching, so I would like the result as shown in intended result:

       

       

      Table-1 Invoice number is Aax/2359, whereas table-2 shows 2359, and since other items ID+Name+Tax rate is matching in both table. The result will be a partial match.

       

       

      • jpessoa8's avatar
        jpessoa8
        Icon for Continued Contributor rankContinued Contributor

        mahenkj2 ,

         

        The key to this issue is the usage of the Fuzzy Merge. This allow the Merge of the two tables by the fields ID, Name and Invoice Number but allowing a match of at least 80% (value by default but can be edited) and ignoring case and spaces.

         

         

        With this Fuzzy Merge with a Full Outer kind you can afterwards compare each combinations and also find if a record is only on one the tables:

         

         

        Final result:

         

         

        Here is a link with the PowerBI file used : https://we.tl/t-DDvMm0z6Wb

         

        Hope this answer solves your problem!
        If you need any additional help please @ me in your reply.
        If my reply provided you with a solution, please consider marking it as a solution โœ”๏ธ or giving it a kudo ๐Ÿ‘
        Thanks!

        You can also check out my LinkedIn!

        Best regards,
        Jorge Pessoa