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
Ajendra
Resolver I
Resolver I

I need Maximum number of "Present" for a particular day.

I have some data of attendance.  i am trying to perform a measure,  So when ever i put that measure along datemaster(calender) in Table it should show only that data whereon max number of people were present. 

DateStatus
18-Mar-23Present
18-Mar-23Present
18-Mar-23Present
15-Mar-23Present
14-Mar-23Absent
12-Mar-23Present
10-Mar-23HD
06-Mar-23Late
02-Mar-23Present
26-Feb-23Present
22-Feb-23Present
20-Feb-23Present
19-Feb-23Present

 

Thanks & Regards,

Ajendra Singh Rawat

1 ACCEPTED SOLUTION

@Ajendra That is what it should be doing, I'll walk you through the code:

Measure = 
    /*
       Get the current date in context assuming you have included Date in your visual
    */
    VAR __Date = MAX('Table'[Date])
    /*
       Return a table filtered to "Present" status
       This table is grouped by Date and __Count column has the count of rows
    */
    VAR __Table = SUMMARIZE(FILTER(ALL('Table'), [Status] = "Present"),[Date],"__Count",COUNTROWS('Table'))
    /*
       Next, we return the maximum count in __Table
    */
    VAR __MaxCount = MAXX(__Table,[__Count])
    /*
       We now return the date that corresponds with the maximum count
       Note, we could have used MINX here as well. Doesn't matter really.
    */
    VAR __MaxCountDate = MAXX(FILTER(__Table,[__Count] = [__Count]),[Date])
    /*
       Now, if the current date (__Date) matches the date for our maximum count,
       we return the maximum count. Otherwise we return BLANK()
    */
    VAR __Result = IF( __Date = __MaxCountDate, __MaxCount, BLANK())
RETURN
    __Result


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...

View solution in original post

5 REPLIES 5
Ajendra
Resolver I
Resolver I

Hi,

i am new here may be not aware of how shoud i ask question or query.

@Greg_Deckler  thanks a ton. for replying and your precious suggetions

 

here are some point please go through.

1. I want to achive this through the Measure only.

2. i want to use that measure in table which already has a date range.

 

Consider below image as output table where Measure has been placed: 

Out.JPG

 

 

Consider below image as raw data table.

Raw.JPG

 

 

Thanks & Regards,

Ajendra Singh

 

@Ajendra OK, try this:

Measure = 
    VAR __Date = MAX('Table'[Date])
    VAR __Table = SUMMARIZE(FILTER(ALL('Table'), [Status] = "Present"),[Date],"__Count",COUNTROWS('Table'))
    VAR __MaxCount = MAXX(__Table,[__Count])
    VAR __MaxCountDate = MAXX(FILTER(__Table,[__Count] = [__Count]),[Date])
    VAR __Result = IF( __Date = __MaxCountDate, __MaxCount, BLANK())
RETURN
    __Result


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...

@Greg_Deckler  Thanks for the support i really appreciate your efforts.

 

but it is looking bit off.

Because i need Date that should be based on Maximum number of "Present"

not Max date and its No. of "Present" 

 

Thanks!

@Ajendra That is what it should be doing, I'll walk you through the code:

Measure = 
    /*
       Get the current date in context assuming you have included Date in your visual
    */
    VAR __Date = MAX('Table'[Date])
    /*
       Return a table filtered to "Present" status
       This table is grouped by Date and __Count column has the count of rows
    */
    VAR __Table = SUMMARIZE(FILTER(ALL('Table'), [Status] = "Present"),[Date],"__Count",COUNTROWS('Table'))
    /*
       Next, we return the maximum count in __Table
    */
    VAR __MaxCount = MAXX(__Table,[__Count])
    /*
       We now return the date that corresponds with the maximum count
       Note, we could have used MINX here as well. Doesn't matter really.
    */
    VAR __MaxCountDate = MAXX(FILTER(__Table,[__Count] = [__Count]),[Date])
    /*
       Now, if the current date (__Date) matches the date for our maximum count,
       we return the maximum count. Otherwise we return BLANK()
    */
    VAR __Result = IF( __Date = __MaxCountDate, __MaxCount, BLANK())
RETURN
    __Result


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...
Greg_Deckler
Community Champion
Community Champion

@Ajendra Sorry, can you elaborate a bit on this? So, you want to show March 18th data? Do you want to just display 18-Mar-23 or ?

 

Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



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...

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.