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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Ezehc02
Regular Visitor

Syntax for Max of sum distincts

Please I am practicing DAX & need help

How do I create a measure which sum up a column by the distinct values of another column and returns the maximum value of the distinct values.

For instance in table 1

I have 2 columns viz; ID & Quantity

IDQuantity
AA2
BB4
CC7
AA2
CC4
AA9
AA2
CC23
BB9
BB5

The measure should return CC as the max of the sum distincts based on Quantity

@amitchandak  and @Jihwan_Kim 

Please help

Thanks alot

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Ezehc02 ,

I created some data:

vyangliumsft_0-1657787144437.png

Here are the steps you can follow:

1. Create measure.

Sum_Group =
CALCULATE(
    SUM('Table'[Quantity]),FILTER(ALL('Table'),
    'Table'[ID]=MAX('Table'[ID])))
Measure =
CALCULATE(MAX('Table'[ID]),FILTER(ALL('Table'),
[Sum_Group]=
MAXX(
    ALL('Table'),[Sum_Group])))

2. Result:

vyangliumsft_1-1657787144438.png

If you need pbix, please click here.

Best Regards,

Liu Yang

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

3 REPLIES 3
Anonymous
Not applicable

Hi  @Ezehc02 ,

I created some data:

vyangliumsft_0-1657787144437.png

Here are the steps you can follow:

1. Create measure.

Sum_Group =
CALCULATE(
    SUM('Table'[Quantity]),FILTER(ALL('Table'),
    'Table'[ID]=MAX('Table'[ID])))
Measure =
CALCULATE(MAX('Table'[ID]),FILTER(ALL('Table'),
[Sum_Group]=
MAXX(
    ALL('Table'),[Sum_Group])))

2. Result:

vyangliumsft_1-1657787144438.png

If you need pbix, please click here.

Best Regards,

Liu Yang

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

Ezehc02
Regular Visitor

Thank you so much @Jihwan_Kim for the help, I learnt alot from your DAX statement and I gave you a thumbs up. But I noticed that when I used this syntax in a table with distinct IDs more than 3, it does not give me the correct figure.

I hoped to get a solution which will sum the unique values, then return the unique ID with the highest sum

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Picture4.png

 

Expected result measure = 
VAR _summarizetable =
    SUMMARIZE ( Data, Data[ID], Data[Quantity] )
VAR _addsumofdistinctquantity =
    SUMMARIZE (
        ADDCOLUMNS (
            _summarizetable,
            "@sumofdistinctquantity",
                SUMX (
                    FILTER ( _summarizetable, Data[ID] = EARLIER ( Data[ID] ) ),
                    Data[Quantity]
                )
        ),
        Data[ID],
        [@sumofdistinctquantity]
    )
VAR _maxsumquantity =
    MAXX ( _addsumofdistinctquantity, [@sumofdistinctquantity] )
RETURN
    SUMMARIZE (
        FILTER ( _addsumofdistinctquantity, [@sumofdistinctquantity] = _maxsumquantity ),
        Data[ID]
    )

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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