Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
pang22
Helper III
Helper III

Write DAX to combine 2 tables

Hello,

 

I have 2 tables (Table 1 & 2) loaded in PowerBI desktop.

How to write a DAX to create a new table to sum the qty by loading month and by factory in PowerBI? Thanks

 

Table 1                                                                                      Table 2

Col name: Order Qty, Factory, Loading month                        Col name: Balance Qty, Suggested Factory, Laoding month

pang22_0-1697684684409.png                                 pang22_2-1697684715688.png

 

Desired outcome, Combine Table 1 & 2:

Col name: Loading month, Combine Factory, Combine Qty

pang22_3-1697684750773.png

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new table.

 

Jihwan_Kim_0-1697691650203.png

 

 

Combined table =
VAR _t =
    SUMMARIZE (
        SELECTCOLUMNS (
            UNION ( Table1, Table2 ),
            "Loading month", Table1[Loading month],
            "Combine Factory", Table1[Factory]
        ),
        [Loading month],
        [Combine Factory]
    )
VAR _addqty =
    ADDCOLUMNS (
        _t,
        "Combine Qty",
            SUMX (
                FILTER (
                    Table1,
                    Table1[Factory] = EARLIER ( [Combine Factory] )
                        && [Loading month] = EARLIER ( [Loading month] )
                ),
                Table1[Order Qty]
            )
                + SUMX (
                    FILTER (
                        Table2,
                        Table2[Suggested Factory] = EARLIER ( [Combine Factory] )
                            && Table2[Loading month] = EARLIER ( [Loading month] )
                    ),
                    Table2[Balance Qty]
                )
    )
RETURN
    _addqty

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new table.

 

Jihwan_Kim_0-1697691650203.png

 

 

Combined table =
VAR _t =
    SUMMARIZE (
        SELECTCOLUMNS (
            UNION ( Table1, Table2 ),
            "Loading month", Table1[Loading month],
            "Combine Factory", Table1[Factory]
        ),
        [Loading month],
        [Combine Factory]
    )
VAR _addqty =
    ADDCOLUMNS (
        _t,
        "Combine Qty",
            SUMX (
                FILTER (
                    Table1,
                    Table1[Factory] = EARLIER ( [Combine Factory] )
                        && [Loading month] = EARLIER ( [Loading month] )
                ),
                Table1[Order Qty]
            )
                + SUMX (
                    FILTER (
                        Table2,
                        Table2[Suggested Factory] = EARLIER ( [Combine Factory] )
                            && Table2[Loading month] = EARLIER ( [Loading month] )
                    ),
                    Table2[Balance Qty]
                )
    )
RETURN
    _addqty

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.