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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

help with complex Measure

Hi, I really apreciate if any one can help me with this problem

 

Data looks like this table

 

ID SchoolLevelServiceQty
101primary schoolLunch20
101primary schoolBreakfast18
101primary schoolsnacks7
101high schoolLunch30
101high schoolBreakfast40

 

Its required a measure that sum max qty by level

 

Max Qty primary school20
Max Qty high school40
Measure result expected60

 

1 ACCEPTED SOLUTION

Hey @Anonymous ,

 

here is a measure that considers more that one grouping columns:

 

 

SUMX across MAX using SUMMARIZE = 
SUMX(
    ADDCOLUMNS(
        SUMMARIZE(
            'Table'
            , 'Table'[ID School]
            , 'Table'[Level]
        )
        , "MaxQty" , CALCULATE( MAX( 'Table'[Qty] ) )
    )
    , [MaxQty]
)

 

 

If I need more than one column inside my iterator table I use SUMMARIZE(...) or table functions that are allowing me to compose tables that are more complex. If there is just one column that determines the table, I use VALUES.

The result:

image.png

Hopefully, this provides what you need to tackle your challenge.

 

So, back to using SUMMARIZECOLUMNS vs SUMMARIZE, depending on your requirements, I would recommend using SUMMARIZECOLUMNS as it is optimized and for this reason, it will perform better, sometimes you will be able to notice this advantage, sometimes you won't, as this will depend on the size of your data.

But, of course, things can become more complex, as the next screenshot shows:

image.png

In the 2nd line of visuals I use the measure "SUMX across MAX using SUMMARIZECOLUMNS":

 

SUMX across MAX using SUMMARIZECOLUMNS = 
SUMX(
    SUMMARIZECOLUMNS(
        'Table'[ID School]
        , 'Table'[Level]
        , "MAXQty" , MAX( 'Table'[Qty] )
    )
    , [MAXQty]
)

 

The measure works inside the card visual but breaks inside the table visual.

 

Explaining why it breaks requires more space than is available here and is already done at least to some extent by the article I mentioned in my previous reply to @KNP . Learning also means developing habits by using patterns, habits then will help us to apply the learned things faster. For this reason, I developed the habit to use SUMMARIZE over SUMMARIZECOLUMNS. Knowing that SUMMARIZE is not as fast as SUMMARIZECOLUMNS.

When I work with large datasets and every millisecond counts, I sometimes write measures just for a single visual, these moments are rare and come up with other problems like model complexity.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

13 REPLIES 13
KNP
Super User
Super User

SumOfMax =
SUMX (
SUMMARIZECOLUMNS (
Table[Level],
"MaxOfLevel", MAX ( Table[Qty] )
),
[MaxOfLevel]
)

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!

Hey,

it's not possible to use SUMMARIZECOLUMNS inside a table iterator.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

@TomMartens - I may be misunderstanding you but my testing would tend to disagree. I'm definitely no DAX expert though.

 

KNP_1-1633492672745.png

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!
Anonymous
Not applicable

thanks, solution works but if I apply a context filter the visual show error

Thanks for the additional example.

I'm not sure what the issue is with the filter. I'd need more detail.

The way I would solve it would be...

SumOfMax =
SUMX (
    SUMMARIZECOLUMNS (
        'Table'[ID School],
        'Table'[Level],
        "GroupedMax", MAX ( 'Table'[Qty] )
    ),
    [GroupedMax]
)

 

May pay to catch up on the conversation I had with Tom above as this may not be considered to be best practice.

Otherwise, maybe wait for @TomMartens to answer, as I'm not sure how to rewrite the "VALUES()" version of the measure to include the two grouping levels you need.

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!

Hey @KNP ,

 

please excuse, I've been a little strict saying

"it's not possible to use SUMMARIZECOLUMNS inside a table iterator",

I should have said

"one should not use SUMMARIZECOLUMNS inside a measure".
This is because the function is not fully supported, for this reason, I do not use it to avoid building habits, which then become a roadblock if I have to rewrite a measure or pattern that I'm trying to adapt to a certain use case where SUMMARIZECOLUMNS can not be used. Here you will find an article, that explains this in much more detail: Introducing SUMMARIZECOLUMNS - SQLBI

 

Once again, please excuse me for being that strict, and of course, the measure works perfectly for this requirement.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom,

 

Thanks for the clarification.

I understand what you're saying. It works in this case but not best practice.

DAX is definitely the weaker part of my skillset so I'm always happy to learn from others.

 

I feel like I should caveat my DAX related answers on here with "I'm no DAX expert", but then again, I feel like all answers in the community come with an implicit caveat. 

 

Regards,

Kim

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!
TomMartens
Super User
Super User

Hey @Anonymous 

 

this measure:

sum over max = 
SUMX(
    VALUES( 'Table'[Level] )
    , CALCULATE( MAX( 'Table'[Qty] ) )
)

returns what you are looking for:

image.png

Using a table iterator function, here SUMX, is necessary because a row header that becomes part of the filter context is not present. As the MAX value has to be calculated for each school level VALUES( level ) is used to determine the table used for iteration. On the total line, There is an iteration across two rows (high school, primary school), inside the body of the table visual there is just one row, as the "row header" implicitly "filters" the table.

 

Hopefully, this provides what you are looking for.

 

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

Hi, thanks! works for the example but still have a little problem, when apply this measure to full table with several ID School don't show the right value,

ID SchoolLevelServiceQty
101primary schoolLunch20
101primary schoolBreakfast18
101primary schoolsnacks7
101high schoolLunch30
101high schoolBreakfast40
602primary schoolLunch10
602primary schoolBreakfast21
602high schoolLunch25
602high schoolBreakfast15


Max qty by service in
ID 101
for primary school is 20,
For high shcool is 40 
in ID 602 
for primary school is 21,
For high shcool is 25

 

Expected measure result is 20+40+21+25 =106 

 

but the measure show 61

 

Thanks for very much for your time 

Hey @Anonymous ,

 

here is a measure that considers more that one grouping columns:

 

 

SUMX across MAX using SUMMARIZE = 
SUMX(
    ADDCOLUMNS(
        SUMMARIZE(
            'Table'
            , 'Table'[ID School]
            , 'Table'[Level]
        )
        , "MaxQty" , CALCULATE( MAX( 'Table'[Qty] ) )
    )
    , [MaxQty]
)

 

 

If I need more than one column inside my iterator table I use SUMMARIZE(...) or table functions that are allowing me to compose tables that are more complex. If there is just one column that determines the table, I use VALUES.

The result:

image.png

Hopefully, this provides what you need to tackle your challenge.

 

So, back to using SUMMARIZECOLUMNS vs SUMMARIZE, depending on your requirements, I would recommend using SUMMARIZECOLUMNS as it is optimized and for this reason, it will perform better, sometimes you will be able to notice this advantage, sometimes you won't, as this will depend on the size of your data.

But, of course, things can become more complex, as the next screenshot shows:

image.png

In the 2nd line of visuals I use the measure "SUMX across MAX using SUMMARIZECOLUMNS":

 

SUMX across MAX using SUMMARIZECOLUMNS = 
SUMX(
    SUMMARIZECOLUMNS(
        'Table'[ID School]
        , 'Table'[Level]
        , "MAXQty" , MAX( 'Table'[Qty] )
    )
    , [MAXQty]
)

 

The measure works inside the card visual but breaks inside the table visual.

 

Explaining why it breaks requires more space than is available here and is already done at least to some extent by the article I mentioned in my previous reply to @KNP . Learning also means developing habits by using patterns, habits then will help us to apply the learned things faster. For this reason, I developed the habit to use SUMMARIZE over SUMMARIZECOLUMNS. Knowing that SUMMARIZE is not as fast as SUMMARIZECOLUMNS.

When I work with large datasets and every millisecond counts, I sometimes write measures just for a single visual, these moments are rare and come up with other problems like model complexity.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

@TomMartens - Thanks for taking the time to explain. The rules around when to use which in DAX is still a bit of a mystery to me. I need to go spend much more time with Alberto and Marco. 😁

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
xOIEmaj

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
image
fabric-SUbadge
Proud to be a Super User!

Together we learn, togehter we grow!



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Jihwan_Kim
Super User
Super User

Picture2.png

 

Result expected measure : =
SUMX ( VALUES ( 'Table'[Level] ), CALCULATE ( MAX ( 'Table'[Qty] ) ) )
 
 

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.