Forum Discussion
help with complex Measure
- 4 years ago
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:
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:
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
Hey,
it's not possible to use SUMMARIZECOLUMNS inside a table iterator.
Regards,
Tom
TomMartens - I may be misunderstanding you but my testing would tend to disagree. I'm definitely no DAX expert though.
- TomMartens4 years agoSuper 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 - SQLBIOnce again, please excuse me for being that strict, and of course, the measure works perfectly for this requirement.
Regards,
Tom
- KNP4 years agoSuper User
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
- Anonymous4 years agoNot applicable
thanks, solution works but if I apply a context filter the visual show error
- KNP4 years agoSuper User
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.