Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Add columns from one table to another table as null columns along with their data types

I have 2 tables viz., Table 1 & Table 2.

Table 1 has standard columns (shown in bold) with some extra columns `Manual col1, `Manual col2, `Manual col3 etc. 

WB Study ID
Commissioning Country
Project Name
Field Start Date
Study Delivery Date
Client
Local Amount
Local Currency
IBP
Finance Coordinator
Study Status
Manual col 1
Manual col 2
Manual col 3
 

Table 2 has only the standard columns (shown in bold):

WB Study ID
Commissioning Country
Project Name
Field Start Date
Study Delivery Date
Client
Local Amount
Local Currency
IBP
Finance Coordinator
Study Status

 

I want to add the extra columns from Table 1 to Table 2, as blank or null columns, but keeping their data types intact. This is so that i can later merge new or updated data in Table 2 to Table 1.

 

Is there a quicker way to do this, instead of writing 3 Table.AddColumn() ?

 

  • You can append an empty copy of Table1 to Table2 and it'll add the extra columns.

    Table.Combine({Table2, Table.SelectRows(Table1, each false)})

     

    To generate this step, go to your Table2 query and click Append Queries (Home tab) then select Table1.

    Then replace Table1 in the generated M code with Table.SelectColumns(Table1, each false).

4 Replies

  • You can append an empty copy of Table1 to Table2 and it'll add the extra columns.

    Table.Combine({Table2, Table.SelectRows(Table1, each false)})

     

    To generate this step, go to your Table2 query and click Append Queries (Home tab) then select Table1.

    Then replace Table1 in the generated M code with Table.SelectColumns(Table1, each false).

    • Anonymous's avatar
      Anonymous
      Not applicable

      The problem is, table1 and table2 are not empty.

      • AlexisOlson's avatar
        AlexisOlson
        Super User

        Why is that a problem? I just explained how to get an empty copy.