Forum Discussion

laurent_rio's avatar
laurent_rio
Icon for Helper I rankHelper I
5 years ago
Solved

Merge 2 tables, please help

Hi,

 

I need to merge my 2 tables 
1st tables = Employee List

Employee ID
1
5
11
12
15


2nd table = Employee Status

Employee IDEmployee Status
1Active
3Terminated
4Terminated
6Terminated

Since Employee ID in table 1 & 2 not sync (  some ID exist in table 1 and some in table 2 only) , i want to combine this 2 table into 1 table 

Employee IDEmployee Status
1Active
3Terminated
4Terminated
5 
6Terminated
11 
12 
15 

 

I try use merge query with mathing column is employee ID on both table and then choose Left Outer as join kind but it will not show me data from table 2 (ID 3,4,6). What should i choose to get the table as i want ?

Please advice

 

  • amitchandak's avatar
    amitchandak
    5 years ago

    laurent_rio , Have you checked my file?

    I added a new column and combined ids.

     

    let
        Source = Table.NestedJoin(Table1, {"Employee ID"}, #"Table (2)", {"Employee ID"}, "Table (2)", JoinKind.FullOuter),
        #"Expanded Table (2)" = Table.ExpandTableColumn(Source, "Table (2)", {"Employee ID", "Employee Status"}, {"Table (2).Employee ID", "Table (2).Employee Status"}),
        #"Added Custom" = Table.AddColumn(#"Expanded Table (2)", "ID", each if [Employee ID] =null then [#"Table (2).Employee ID"] else [Employee ID]),
        #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Employee ID", "Table (2).Employee ID"})
    in
        #"Removed Columns"

     

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi laurent_rio ,

    If you still want to keep the original tables(Employee List and Employee Status), you can add new blank query with the following codes in Advanced Editor to get the combined data.

    let
        Source = Table.Combine({#"Employee Status", #"Employee List"}),
        #"Removed Duplicates" = Table.Distinct(Source, {"Employee ID"})
    in
        #"Removed Duplicates"

    Best Regards

6 Replies

  • Hi,

     

    I try with full outer but when i try to expand and show the employee status. The employee ID that not in table 1 is dissapear

  • Hi new table using full outer will be like this, the employee ID from table 2 is return as null. Any way to display employee ID in table 2 ?

     

     

    • amitchandak's avatar
      amitchandak
      Icon for Super User rankSuper User

      laurent_rio , Have you checked my file?

      I added a new column and combined ids.

       

      let
          Source = Table.NestedJoin(Table1, {"Employee ID"}, #"Table (2)", {"Employee ID"}, "Table (2)", JoinKind.FullOuter),
          #"Expanded Table (2)" = Table.ExpandTableColumn(Source, "Table (2)", {"Employee ID", "Employee Status"}, {"Table (2).Employee ID", "Table (2).Employee Status"}),
          #"Added Custom" = Table.AddColumn(#"Expanded Table (2)", "ID", each if [Employee ID] =null then [#"Table (2).Employee ID"] else [Employee ID]),
          #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Employee ID", "Table (2).Employee ID"})
      in
          #"Removed Columns"

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi laurent_rio ,

    If you still want to keep the original tables(Employee List and Employee Status), you can add new blank query with the following codes in Advanced Editor to get the combined data.

    let
        Source = Table.Combine({#"Employee Status", #"Employee List"}),
        #"Removed Duplicates" = Table.Distinct(Source, {"Employee ID"})
    in
        #"Removed Duplicates"

    Best Regards