Forum Discussion
Finding Max Days per row
- 1 year ago
Hi srlabhe
Try this:
CO with top days = CALCULATE ( -- Get the CO with the highest [Days CO] in the current filter context MAXX ( TOPN ( 1, -- Create a table of COs with their corresponding [Days CO] values SUMMARIZECOLUMNS ( 'Table'[CO], "@value", [Days CO] ), [@value], DESC -- Sort descending by [Days CO] and take top 1 ), [CO] -- Return the CO name (could also use [@value] to return the max value) ), ALLSELECTED () -- Respect slicers and visuals while removing row context )
Hi srlabhe ,
Looking at this thread, I notice there's some overcomplicated DAX being suggested when simpler solutions would work better.
For your specific requirement:
MO =
VAR MaxDaysInGroup =
CALCULATE(
MAXX(
ALLEXCEPT(Table, Table[Eid]),
[Days CO]
)
)
RETURN
CALCULATE(
SELECTEDVALUE(Table[CO]),
FILTER(
ALLEXCEPT(Table, Table[Eid]),
[Days CO] = MaxDaysInGroup
)
)
Days MO =
CALCULATE(
MAXX(
ALLEXCEPT(Table, Table[Eid]),
[Days CO]
)
)Why this approach works well:
- Uses the reliable ALLEXCEPT pattern that handles measure context properly
- Avoids complex table functions that can behave inconsistently across different DAX engine versions
- More maintainable and easier to debug
Alternative using the measure aggregation pattern mentioned earlier:
Days MO = MAXX(
SUMMARIZE(
ALLEXCEPT(Table, Table[Eid]),
Table[CO],
"@DaysCO", [Days CO]
),
[@DaysCO]
)The key insight here is that when working with measures in calculated columns or other measures, you want to use patterns that have proven stability rather than newer functions that might have edge cases or version dependencies.
Both approaches handle your Eid-level grouping correctly while finding the CO with maximum days.
If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
Note: As Einstein said, "Everything should be made as simple as possible, but not simpler" - this applies perfectly to DAX solutions.
This response was assisted by AI for translation and formatting purposes.
MO is already available in data , we nee dto calculate Days MO and the formula you provided not working