Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

after union two table, data go to wrong column

when I union two same table, most data go to wrong column,  who know how to fix this error, thank you

  • Hi Anonymous,

     

    You could modify the DAX for calculated table as:

    Result Table =
    UNION (
        SELECTCOLUMNS (
            Table1,
            "Column1", Table1[Column1],
            "Column2", Table1[Column2],
            "Column3", Table1[Column3]
        ),
        SELECTCOLUMNS (
            Table2,
            "Column1", Table2[Column1],
            "Column2", Table2[Column2],
            "Column3", Table2[Column3]
        )
    )

    That way can keep the same order for columns when you union two tables.

     

    Regards,

    Yuliana Gu

9 Replies

  • I never used union as such, did you tried using "append" in power queyr and see if it works.

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi Anonymous,

     

    This problem is caused by the different column orders of two tables.

     

    The displayed column order in table view is not matched with that in the right fields pane. Please see below example:

     

    Best regards,

    Yuliana Gu

    • Anonymous's avatar
      Anonymous
      Not applicable

      Yes, true, two table column have different order like your example, how to fix this without code ?

      How to let data to show  with right side column order? 

      in the Edit Query Mode, my table with same column order, how they change column order by Data tab?

      Thank you for your help

      • v-yulgu-msft's avatar
        v-yulgu-msft
        Microsoft Employee

        Hi Anonymous,

         

        You could modify the DAX for calculated table as:

        Result Table =
        UNION (
            SELECTCOLUMNS (
                Table1,
                "Column1", Table1[Column1],
                "Column2", Table1[Column2],
                "Column3", Table1[Column3]
            ),
            SELECTCOLUMNS (
                Table2,
                "Column1", Table2[Column1],
                "Column2", Table2[Column2],
                "Column3", Table2[Column3]
            )
        )

        That way can keep the same order for columns when you union two tables.

         

        Regards,

        Yuliana Gu