Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

How to combine 2 tables into 1

Hi, how can I combine the below 2 tables to the expected output table?

 

Table 1:

JobOrder
J-123O-123
J-234O-123
J-345 
J-456O-345
J-567O-567

 

Table 2:

OrderProductQty
O-123A2
O-123B4
O-123C5
O-567A1
O-567B2
O-567C3

 

Expected Output:

 

  • Anonymous's avatar
    Anonymous
    5 years ago

    HI Anonymous,

    Perhaps you can consider adding buffer functions to your M query expression to reduce the calculation spends.

    Nested functions and Table.Buffer() - Exceed

    BTW, what type of data source are you worked on? If you mean the data source which supports additional statements, I'd like to suggest you enable the advanced option and using query statement to directly export the result table. They will have better performance than do these operations on the query editor side.

    Power Query SQL Server connector | Microsoft Docs
    Regards,

    Xiaoxin Sheng

8 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Ashish_Mathur , the expected output is as shown in the screenshot below. J-345 and J-456 have no order and product. 

       

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

    From your Table 1 query, merge in Table 2 on the Order # columns (use Merge button in the ribbon), and then expand the column of "Table"s.

     

    Pat

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi mahoneypat , Table 2 is very large and it may affect the performance of Table 1 if I use Merge function. Is there any way to create a relationship for these 2 tables?

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

    Yes, you can create that relationship in the diagram view.  However, that will create a many-to-many relationship, which is not a good practice.  Typically, a bridge table is make to connect to both tables, in your case a table with one row for each Order.  This table would then connect 1:M with both of your tables shown.  However, I don't know your data and what analyses/visualizations you plan to make to know if that makes sense in your case.

     

    Pat