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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
SushmaReddy
Helper I
Helper I

Get the count of records for Max date

Hi Team,

The requirement is to get the count of materials for Max date.

The below logic is getting the distinct count where i want to display the count.

VAR _M = SUMMARIZE(T1,T1[Material],
"MAX",MAX(T1[Date]),
"Status",CALCULATE(MAX(T1[Status]),
FILTER(T1,T1[Material]=EARLIER(T1[Material]))))
return
COUNTROWS(FILTER(_Mat,[Status]="Failed"))+0
Mat   Date               Status     Error
123   03-06-2022     Failed    GMDN required
123   03-06-2022     Failed    FDA required
The count should be 2
Thanks in advance
1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @SushmaReddy ,

You could create a measure or column as follow:

1.measure:

count = var _max=CALCULATE(MAX('T1'[Date]),ALLSELECTED(T1))
return CALCULATE(COUNT(T1[Material]),FILTER(ALLSELECTED(T1),[Material]=MAX('T1'[Material])&&[Date]=_max&&[Status]="Failed"))

2. column:

Column = 
 var _max=MAX('T1'[Date])
return CALCULATE(COUNT(T1[Material]),FILTER(ALLSELECTED(T1),[Material]=EARLIER('T1'[Material])&&[Date]=_max&&[Status]="Failed"))

The final show:

vyalanwumsft_0-1656987037773.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
SushmaReddy
Helper I
Helper I

The code is working and getting the correct count ....Thank you for the help

v-yalanwu-msft
Community Support
Community Support

Hi, @SushmaReddy ,

You could create a measure or column as follow:

1.measure:

count = var _max=CALCULATE(MAX('T1'[Date]),ALLSELECTED(T1))
return CALCULATE(COUNT(T1[Material]),FILTER(ALLSELECTED(T1),[Material]=MAX('T1'[Material])&&[Date]=_max&&[Status]="Failed"))

2. column:

Column = 
 var _max=MAX('T1'[Date])
return CALCULATE(COUNT(T1[Material]),FILTER(ALLSELECTED(T1),[Material]=EARLIER('T1'[Material])&&[Date]=_max&&[Status]="Failed"))

The final show:

vyalanwumsft_0-1656987037773.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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.