Forum Discussion

kferrone's avatar
kferrone
Regular Visitor
9 years ago

Union thinks column numbers are different

I am trying to make a union between two of the same table. I am following a tutorial on how to make tables incrementally load: Incrementally Load tables.

First I import the original tables the default PowerBI way which imports every column into a table. On those tables you can right click and view the source query which I copied and pasted into a new table where I simply add a where clause to the end to narrow in on the new data.

Then I go to modeling in the ribbon and create a new table with a union like so: tbl_union = UNION('tbl_old_data','tbl_new_data').

The issue is sometimes the tables will Union together just fine, then others will complain the number of columns don't match up.
The error message: "Each table argument of 'UNION' must have the same number of columns."

Each table I did this to, I followed the same exact process. It is really weird only some tables get this error and others don't. I have a feeling the problem is due to some kind of type mismatch with a column from each table. I'm pretty sure the default import is importing some columns as a different type than when the data came from a query.

Can anyone help clarify what is wrong here?

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi kferrone,

     

    If you can't ensure these columns will be changed, you can try to use SELECTCOLUMNS function to choose specific columns.

    Merged Table= 
    UNION(
    SELECTCOLUMNS('Table1',"COLUMN1",[Column1],"COLUMN2",[Column2],...),
    SELECTCOLUMNS('Table2',"COLUMN1",[Column1],"COLUMN2",[Column2],...),
    SELECTCOLUMNS('Table3',"COLUMN1",[Column1],"COLUMN2",[Column2],...)
    )

     

    You can also try use Table.InsertRows(Power query) to merge there tables.

     

    In addition, if above not help, can you please share some sample data to test?

     

    Regards,

    Xiaoxin SHeng

    • amay15's avatar
      amay15
      Frequent Visitor

      Thank you. This really helped:)

    • Anonymous's avatar
      Anonymous
      Not applicable

      I get this error even when using ADDCOLUMS to choose my colums from each table. Why does UNION think I don't have the same number of columns from each table?