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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Need a dax formula to get the max count in a grouping

Hello!

 

I have the below table, and what I need, for a period, the max number of people on a day. For example:

 

PersonDaySchedule
John01/01/2021Morning
Esther02/01/2021Evening
Maria01/01/2021Morning
Pedro01/01/2021Evening
John02/01/2021Morning

 

Outcome:

If I filter by all dates it will give me: 2. That is at some point I will need two people.

 

If I filter by only 1 January in the morning, it will return: 1, as in one person max needed.

 

In my mind is getting a MAXX that will be applied to a table, counting the rows and grouping dates and schedule. But don't know how.

 

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

At the end I combined MAXX, SUMMARIZE and DISTINCTCOUNT

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

At the end I combined MAXX, SUMMARIZE and DISTINCTCOUNT

Anonymous
Not applicable

The above is almost what I wanted. My mistake, it has to count distinct (I wish there was a COUNTDISTINCTX). For example at the bottom, for  Day 01/01/2021 and Morning, it's two unique people.

 

PersonDaySchedule
John01/01/2021Morning
Esther02/01/2021Evening
Maria01/01/2021Morning
Pedro01/01/2021Evening
John02/01/2021Morning
John01/01/2021Morning

 

Any ideas?

Icey
Community Support
Community Support

Hi @Anonymous ,

 

Create two measures.

Measure = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Person] ),
    ALLEXCEPT ( 'Table', 'Table'[Day], 'Table'[Schedule] )
)
Measure 3 = MAXX('Table',[Measure])

count.gif

 

 

Best Regards,

Icey

 

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

Greg_Deckler
Super User
Super User

@Anonymous Are you sure that you meant 1 January and not 2 January is when you need 2 people? Because...the data...

 

In any case, I think what you want is:

Measure = 
    VAR __Table = GROUPBY('Table',[Day],[Schedule],"__Count",COUNTX(CURRENTGROUP(),[Person]))
RETURN
    MAXX(__Table,[__Count])

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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