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
leodavinci
Regular Visitor

Summarize table based on sum of a column

Hello, 

 

in Power BI desktop I'm trying to summarize the table below.

The result I want is a table with only one ID and the related Brand with the highest quantity (obtained by summing up all the quantity for the same Brand on each ID).

 

imagebi.JPG

 

I tried to create a calculated table with the formula below, but rhe result is not correct.

 

Table2 =

SUMMARIZE(Table1,

Table1[ID],

Table1[Brand],

"TotalQuantity",

SUMX(Table1, Table1[Quantity])

)


I'd be greatful if someone could suggest a better formula or different method.
1 ACCEPTED SOLUTION
v-weiyan1-msft
Community Support
Community Support

Hi @leodavinci ,

 

Based on your description,
Please try the following steps:
My Sample:

vweiyan1msft_0-1705487967521.png

1. Please try code as below to Create a Calculated table.

GroupTable = GROUPBY (
    'Table',
    'Table'[ID],
    'Table'[Brand],
    "@Quantity", SUMX(CURRENTGROUP(), 'Table'[Quantity])
)

2. Use the following code to create two Measures.

Max_Quantity = MAXX(
                    FILTER(ALL(GroupTable),'GroupTable'[Table_ID] = MAX('GroupTable'[Table_ID])),
                    'GroupTable'[@Quantity]
                )
Max_Quantity_Corresponding Brand = MAXX(FILTER(ALL(GroupTable),
                                        'GroupTable'[@Quantity] = [Max_Quantity] && 'GroupTable'[Table_ID] = MAX('GroupTable'[Table_ID])) 
                                        ,'GroupTable'[Table_Brand])

Result is as below.

vweiyan1msft_1-1705488178562.png

 

Best Regards,
Yulia Yan

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

2 REPLIES 2
v-weiyan1-msft
Community Support
Community Support

Hi @leodavinci ,

 

Based on your description,
Please try the following steps:
My Sample:

vweiyan1msft_0-1705487967521.png

1. Please try code as below to Create a Calculated table.

GroupTable = GROUPBY (
    'Table',
    'Table'[ID],
    'Table'[Brand],
    "@Quantity", SUMX(CURRENTGROUP(), 'Table'[Quantity])
)

2. Use the following code to create two Measures.

Max_Quantity = MAXX(
                    FILTER(ALL(GroupTable),'GroupTable'[Table_ID] = MAX('GroupTable'[Table_ID])),
                    'GroupTable'[@Quantity]
                )
Max_Quantity_Corresponding Brand = MAXX(FILTER(ALL(GroupTable),
                                        'GroupTable'[@Quantity] = [Max_Quantity] && 'GroupTable'[Table_ID] = MAX('GroupTable'[Table_ID])) 
                                        ,'GroupTable'[Table_Brand])

Result is as below.

vweiyan1msft_1-1705488178562.png

 

Best Regards,
Yulia Yan

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

ray_aramburo
Super User
Super User

Do you need the table explicitly on your dataset? If so, just go to Power Query > Group By > Select ID, Brand columns and group by sum of quantity.

If not, just use a table visual and add the fields ID, Brand and Quantity. Power BI will automatically add up the quantity if it's set as a numerical column. 





Did I answer your question? Give your kudos and mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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