Forum Discussion

Gozde's avatar
Gozde
Icon for Helper I rankHelper I
8 years ago
Solved

Add rows to table according to grouping in different table

Hi,

 

I would like to add rows to one table ( or combine two tables) according to group number from another table.

 

These are what I have:

Table 1
NamePart
Ax1
By1
Bx1

 

Table 2
GroupPart 
1x1
1x2
2y1
2y2

 

This is what I am looking for

Final Table  
NamePartGroup
Ax11
Ax21
By12
By22
Bx11
Bx21

 

 

I already tried merge/append or DAX code (Union or OuterJoin) and not succeed.

 

Do you have any recommendation? :)

 

Thank you!

Gozde

12 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Icon for Community Champion rankCommunity Champion

    Hi Gozde

     

    Please try this calculated table

     

    New Table =
    VAR Mytable1 =
        ADDCOLUMNS (
            Table1,
            "My Group", CALCULATE ( FIRSTNONBLANK ( Table2[Group], 1 ) )
        )
    VAR JoinTables =
        GENERATE (
            SELECTCOLUMNS ( mytable1, "Name", [Name], "My Group", [My Group] ),
            FILTER ( Table2, Table2[Group] = [My Group] )
        )
    RETURN
        SELECTCOLUMNS ( JoinTables, "Name", [Name], "Group", [Group], "Part", [Part] )