Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Merge tables using Direct Query

I want to combine two tables with different number of columns. Both tables has same common fields as A & B and would like to combine that will result to a table having fields: A, B, C, D, E, F, G, H...
  • Akash_Varuna's avatar
    1 year ago

    Hi Anonymous  Create a UNION SQL query combining the tables, ensuring missing columns are filled with NULL and matching fields like A and B align. Use Advanced Query Editor in Power BI to input the query in DirectQuery mode. Verify data types of common fields (A and B) match in both tables for proper merging.

  • PijushRoy's avatar
    1 year ago

    Hi Anonymous 
    Can you please try similar SQL Code for your solution in Direct Query mode
    Write this SQL in SQL Query box

    SELECT
        T1.KEY FIELDA,
        T1.KEY FIELDB,
        T1.COLUMN C,
        T1.COLUMN D,
        T1.COLUMN E,
        T1.COLUMN F,
        T2.COLUMN G,
        T2.COLUMN H,
        T2.COLUMN I,
        T2.COLUMN J
    FROM
        TABLE1 T1
    FULL OUTER JOIN
        TABLE2 T2 ON T1.KEY FIELDA = T2.KEY FIELDA AND T1.KEY FIELDB = T2.KEY FIELDB;