I have 2 input Tables. Input Table1 is the source data and input Table 2 is a criteria table.
+--------------------------+----------+ +--------------------------+-------+
| TABLE 1 (Source data) | | TABLE 2 (Criterias) |
+-------------------------------------+ +----------------------------------+
+-------------------------------------+ +----------------------------------+
| DESCRIPTION | VALUE | | PREFIX | CODE |
+-------------------------------------+ +----------------------------------+
| ID | 0 | | 7235 | ABX1 |
| NAME | JFMSC | | 3553 | POWQ |
| TYPE | UHELQ | | 7459 | UWEER |
| DFRUL | F4 | | 10012 | ABX1 |
| ADDR | 10012002 | | 430 | ABX1 |
| RRUL | P1 | +--------------------------+-------+
| ADDR | 723 |
| RRUL | P1 |
| ID | 2 |
| NAME | PLLSJS |
| TYPE | UHELQ |
| DFRUL | P3 |
| ID | 4 |
| NAME | AAAARR |
| TYPE | UHELQ |
| DFRUL | T7 |
| ADDR | 35531156 |
| RRUL | P1 |
| ADDR | 72358 |
| RRUL | P1 |
| ADDR | 86401 |
| RRUL | K9 |
| ID | 0 |
| NAME | PPROOA |
| TYPE | RRHN |
| DFRUL | P1 |
| ADDR | 43001 |
| RRUL | T8 |
| ADDR | 7459001 |
| RRUL | D4 |
| ADDR | 430457 |
| RRUL | W2 |
| ADDR | 745913 |
| RRUL | P1 |
| ADDR | 74598001 |
| RRUL | Y5 |
+--------------------------+----------+
My goal is to get the an output table like below (Would be the Table #4), that shows the CODE that is THE MOST similar compared with each number of field "ADDR" based on criterias of "TABLE 2". If there are repeated CODEs for each ID, I only want to show one (unique codes list).
I explain in more detail in Sample file attached here SampleV1.xlsx.
I want to Transform the data based in Input Table 1 and 2 to get an output table like this (Desired OUTPUT TABLE #2 in file attached):
+----+--------+-------+-------+-------+------+
| ID | NAME | TYPE | DFRUL | CODE | RRUL |
+----+--------+-------+-------+-------+------+
| 0 | JFMSC | UHELQ | P1 | ABX1 | P1 |
| 2 | PLLSJS | UHELQ | P3 | | |
| 4 | AAAARR | UHELQ | T7 | POWQ | P1 |
| | | | | ABX1 | P1 |
| | | | | 86401 | K9 |
| 0 | PPROOA | RRHN | P1 | ABX1 | P1 |
| | | | | UWEER | P1 |
+----+--------+-------+-------+-------+------+
I hope someone could help me with this. Thanks in advance.