Forum Discussion
pang22
Helper III
3 years agoWrite 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 ...
- 3 years ago
Hi,
Please check the below picture and the attached pbix file.
It is for creating a new table.
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
Jihwan_Kim
Super User
3 years agoHi,
Please check the below picture and the attached pbix file.
It is for creating a new table.
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