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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

SUMMARIZE, SUMMARIZECOLUMNS, GROUPBY for multiple tables

Hi,

 

I have 2 separate tables in Power BI model and I want to combine them into 1 table.

image.png

 

image.png


Here is the result I want to see by using DAX expression:

image.png

 

The table format for TableA and TableB is different and they are not exactly the same.

How can I use either of the SUMMARIZE, SUMMARIZECOLUMNS or GROUPBY functions to do it with DAX? I tried all of them but seems not running properly with the expected result.

I want the result to display in the data tab (not the report tab) in Power BI Desktop.

 

Thanks.

 

Best regards,

Emily

 

1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

First, create relationship between the two tables with [ID] column.

Second, create a measure:

 

Measure 5 = MAX(Sheet5[Qty]) + MAX(Sheet6[Qty])

 

aa8.PNG

 

But, if your the second table like this:

aa9.PNG

You need to create a calculated table:

 

Table = 
UNION(
    Sheet5,Sheet6
)

 

aa10.PNG

 

If you want to create fact table, you can do like this:

Create two calculated tables:

Table = 
UNION(
   SELECTCOLUMNS(Sheet5, "ID", Sheet5[ID], "Qty", Sheet5[Qty]),
   SELECTCOLUMNS(Sheet6, "ID", Sheet6[ID], "Qty", Sheet6[Qty])
)

Table 2 = 
SUMMARIZE(
    'Table',
    'Table'[ID],
    "Qty",
    SUM('Table'[Qty])
)

aa11.PNG

 

Best regards,
Lionel Chen

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

View solution in original post

7 REPLIES 7
v-lionel-msft
Community Support
Community Support

Hi @Anonymous ,

 

First, create relationship between the two tables with [ID] column.

Second, create a measure:

 

Measure 5 = MAX(Sheet5[Qty]) + MAX(Sheet6[Qty])

 

aa8.PNG

 

But, if your the second table like this:

aa9.PNG

You need to create a calculated table:

 

Table = 
UNION(
    Sheet5,Sheet6
)

 

aa10.PNG

 

If you want to create fact table, you can do like this:

Create two calculated tables:

Table = 
UNION(
   SELECTCOLUMNS(Sheet5, "ID", Sheet5[ID], "Qty", Sheet5[Qty]),
   SELECTCOLUMNS(Sheet6, "ID", Sheet6[ID], "Qty", Sheet6[Qty])
)

Table 2 = 
SUMMARIZE(
    'Table',
    'Table'[ID],
    "Qty",
    SUM('Table'[Qty])
)

aa11.PNG

 

Best regards,
Lionel Chen

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

Ashish_Mathur
Super User
Super User

Hi,

I'd suggest that you rename the third column in both tables to Item.  Then use the Append functionality in the Query Editor to combine both datasets.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

Try like

summarize(
union(
selectcolumns(Table1,"ID",Table1[ID],"QTY",Table1[QTY]),
selectcolumns(Table2,"ID",Table2[ID],"QTY",Table2[QTY])
),[ID],"QTY SUM",sum([QTY]))

 

Appreciate your Kudos.

Anonymous
Not applicable

@amitchandak 

I tried your proposed answer but I got the following error message, can you please assist?

image.png

 

 

Many thanks!

 

Best regards,

Emily

Is not suggesting [QTY] (With square bracket)

 

Otherwise, try

Table =
var _tab =union(
selectcolumns(Table1,"ID",Table1[ID],"QTY",Table1[QTY]),
selectcolumns(Table2,"ID",Table2[ID],"QTY",Table2[QTY])
)
return
summarize(_tab,[ID],"QTY SUM",sum([QTY]))

 Appreciate your Kudos.

Anonymous
Not applicable

@amitchandak 

No.....revised one still not working...

Can you assist? Thanks.

image.png

 

Best regards,

Emily

 

Try like

Table =
var _tab =union(
selectcolumns(Table1,"ID",Table1[ID],"_QTY",Table1[QTY]),
selectcolumns(Table2,"ID",Table2[ID],"_QTY",Table2[QTY])
)
return
summarize(_tab,[ID],"QTY SUM",sum([_QTY]))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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