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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
srlabhe
Helper V
Helper V

Finding Max Days per row

Hi PBI Gurus

I have below data 

srlabhe_0-1753986288996.png

 

Where Days CO is a measure calculated based on selected date in slicer like below

=
var _maxDate=[MaxAsOfDateSelected]
var _diff=
NETWORKDAYS(SELECTEDVALUE(Table[Date]),_maxDate)
return
_diff
Now I wanted to have MO and Days MO Calculated as 
MO= CO who has max no of days 
Days MO= No of Days of MO
SO ideally it shoudl look like below 
srlabhe_1-1753986428856.png

I tried to use AllExcept , Selected Value , MAxx but its not working, I see its simple but something is missing.

Help appreciated 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

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
)

danextian_0-1754020462997.png

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

15 REPLIES 15
v-dineshya
Community Support
Community Support

Hi @srlabhe ,

Thank you for reaching out to the Microsoft Community Forum.

 

I have created MO and Days MO Measure.

 

Please refer below output snap and attached PBIX file.

vdineshya_0-1754043732099.png

 

I hope this information helps. Please do let us know if you have any further queries.

 

Regards,

Dinesh

burakkaragoz
Community Champion
Community Champion

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 

danextian
Super User
Super User

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
)

danextian_0-1754020462997.png

 

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Allselected()  -- Respect slicers and visuals while removing row context

Seems this is the issue , I want the Max of Days CO to refletc for each Eid even if the visual is not filtered

Its not working as expected

Days with MO shows as below if not filtered for ant Eid

srlabhe_0-1754057106079.png

 

Sorry but when I go to summary level it shows me sum of all and not Eid level data ....

Greg_Deckler
Community Champion
Community Champion

@srlabhe This looks like a measure aggregation problem. See my blog article about that here: https://community.powerbi.com/t5/Community-Blog/Design-Pattern-Groups-and-Super-Groups/ba-p/138149 

The pattern is:
MinScoreMeasure = MINX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
MaxScoreMeasure = MAXX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
AvgScoreMeasure = AVERAGEX ( SUMMARIZE ( Table, Table[Group] , "Measure",[YourMeasure] ), [Measure])
etc.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hmm,

is there any way we check if MO=CO then take Days CO and print it on all rows of the Eid?

techies
Super User
Super User

Hi @srlabhe please try this calculated column

 

Days MO =
CALCULATE(
    MAX('TaskTable'[Days CO]),
    ALLEXCEPT('TaskTable', 'TaskTable'[Eid])
)
 
 
MO =
VAR _maxDays =
    CALCULATE(
        MAX('TaskTable'[Days CO]),
        ALLEXCEPT('TaskTable', 'TaskTable'[Eid])
    )
RETURN
CALCULATE(
    MAX('TaskTable'[CO]),
    FILTER(
        'TaskTable',
        'TaskTable'[Days CO] = _maxDays &&
        'TaskTable'[Eid] = EARLIER('TaskTable'[Eid])
    )
)
 
 
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

While calculating Days MO it gives me below error

The MAX function only accepts a column reference as the argument number 1.

@srlabhe Correct, since it is a measure, you have to do it via measure aggregation as I mentioned.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

So it should be in my case 

Days MO=maxx(summarize(Table,Eid,"Measure", [Days CO]),[Days CO])

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors