Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Union - Wrong columns

Hello, I'm trying to do a Union between two tables and the data doesn't go in the right columns. I know that I need to use selectcolumns in order to keep the data lineage, but my formula is more complicated than the examples given on the Web and I can't figure it out.  Here's the formula and the wrong table result. Thank you

 

TABLE3 =
UNION (
              'Table',
              FILTER (
                    ADDCOLUMNS (
                            SUMMARIZE ( CROSSJOIN ( 'Date', 'Table' ), 'Date'[Date], 'Table'[Produit] ),
                            "Commande", "zz",
                            "Ventes", IF ( ISBLANK ( [Ventes_] ), 0, ( [Ventes_] ) )
                          ),
                          [Ventes] = 0
               )
)

 

 

  • Hi Anonymous 

     

    I think the problem is that you frist summarize and then add the column and this is was determeines the order of the second table. DId you thought about changing the order of the first table?

     

    TABLE3 =
    UNION (
                 
                  SELECTCOLUMNS(
                     'Table',
                     "Date",[Date],
                     "Produit",[Produit],
                     "Commande",[Commande],
                    "Ventes",[Ventes]
                  )
                  ,
                  FILTER (
                        ADDCOLUMNS (
                                SUMMARIZE ( CROSSJOIN ( 'Date''Table' ), 'Date'[Date]'Table'[Produit] ),
                                "Commande""zz",
                                "Ventes"IF ( ISBLANK ( [Ventes_] ), 0, ( [Ventes_] ) )
                              ),
                              [Ventes] = 0
                   )
    )

     

    Best regards
    Michael
    -----------------------------------------------------
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    Appreciate your thumbs up!
    @ me in replies or I'll lose your thread.

2 Replies

  • Mikelytics's avatar
    Mikelytics
    Resident Rockstar

    Hi Anonymous 

     

    I think the problem is that you frist summarize and then add the column and this is was determeines the order of the second table. DId you thought about changing the order of the first table?

     

    TABLE3 =
    UNION (
                 
                  SELECTCOLUMNS(
                     'Table',
                     "Date",[Date],
                     "Produit",[Produit],
                     "Commande",[Commande],
                    "Ventes",[Ventes]
                  )
                  ,
                  FILTER (
                        ADDCOLUMNS (
                                SUMMARIZE ( CROSSJOIN ( 'Date''Table' ), 'Date'[Date]'Table'[Produit] ),
                                "Commande""zz",
                                "Ventes"IF ( ISBLANK ( [Ventes_] ), 0, ( [Ventes_] ) )
                              ),
                              [Ventes] = 0
                   )
    )

     

    Best regards
    Michael
    -----------------------------------------------------
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    Appreciate your thumbs up!
    @ me in replies or I'll lose your thread.