Forum Discussion

Pikachu-Power's avatar
Pikachu-Power
Impactful Individual
5 years ago
Solved

UNION DISTINCT question

hi all,

 

i found following way to combine two distinct tables and use UNION like in SQL (without double entries):

 

TABLE_X =

UNION (
SUMMARIZE(Table1, Table1[A], Table1[B], Table1[C]),
SUMMARIZE(Table2, Table2[A], Table2[B], Table2[C])
)
 
TABLE_Y =
SUMMARIZE(Table_X, Table_X[A], Table_X[B], Table_X[C])
 
Is it possible to write that in one measure? a better dax formular is also welcome ðŸ™‚
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi  Pikachu-Power ,

    You can write this DAX:

    TABLE =
    Var _X= UNION (
    SUMMARIZE(Table1, Table1[A], Table1[B], Table1[C]),
    SUMMARIZE(Table2, Table2[A], Table2[B], Table2[C])
    )
    Return 
    SUMMARIZE(_X,[A], [B], [C])

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • mahoneypat's avatar
    mahoneypat
    Microsoft Employee

    You can try this expression

     

    NewTable =

    var TableX = UNION (
    SUMMARIZE(Table1, Table1[A], Table1[B], Table1[C]),
    SUMMARIZE(Table2, Table2[A], Table2[B], Table2[C])
    )
     
    Return
    SUMMARIZE(TableX, Table1[A], Table1[B], Table1[C])
     
    Pat
    • Pikachu-Power's avatar
      Pikachu-Power
      Impactful Individual
      Thanks. Seems to work. But shouldnt we use somethink like:
       
      ...
      Return
      SUMMARIZE(TableX, TableX[A], TableX[B], TableX[C])
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  Pikachu-Power ,

    You can write this DAX:

    TABLE =
    Var _X= UNION (
    SUMMARIZE(Table1, Table1[A], Table1[B], Table1[C]),
    SUMMARIZE(Table2, Table2[A], Table2[B], Table2[C])
    )
    Return 
    SUMMARIZE(_X,[A], [B], [C])

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.