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! Request now

Reply
ben-t
Frequent Visitor

Count based on max date

Hi all , 
I'm trying to do a distinct count of locations based on their last status date.
the locations need to fufil 3 criteria, prefix, dept and changedate before the max slicer date selected
Eg: for July, both locations fufil all 3 criteria, so count should be 2

but for august, location 702 should be counted, but 701 should not be. 

How can i use a measure to count rows based on max change date < max selected dates? Thanks

bent_0-1631688726067.png

 

location count = CALCULATE(distinctCOUNT(Locations[locations.location]),FILTER(Locations,Locations[locations.prefix] in ALLSELECTED('dept prefix'[Prefix]) && Locations[locations.department] in ALLSELECTED('dept prefix'[Department]) && MAX(Locations[locations.changedate])<= MAX('Date Table'[Date])))
1 ACCEPTED SOLUTION

@ben-t , if date table is not joined

 

new measure =
var _date = MAXX(allselected('Date Table'), 'Date Table'[Date])
return
CALCULATE(distinctCOUNT(Locations[locations.location]),FILTER(Locations, Locations[locations.changedate]<= _max))

 

if joined with date on change date

 

new measure =
var _date = MAXX(allselected('Date Table'), 'Date Table'[Date])
return
CALCULATE(distinctCOUNT(Locations[locations.location]),FILTER(all(Date Table'), 'Date Table'[Date]<= _max))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @ben-t 

Have you solved your problem? If yes,  could you kindly mark the answer helpful as the solution? 
If not, could you provide more details about your problem? so that we can work on it further. Thanks.


Best Regards,
Community Support Team _ Tang

v-xiaotang
Community Support
Community Support

Hi @ben-t 

I think your measure is right, for august, one row of location 701 fullfils 3 criteria, but another not. so the distinctCOUNT of location should be 2. (row2 & row3)

vxiaotang_0-1631863114482.png

If I miss anything, please let me know. and could you share your sample file? so that we can check the measure further.

 

 

Best Regards,

Community Support Team _Tang

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

ben-t
Frequent Visitor

Or is it possible to create a dax table where i can have distinct rows of each location, based on the max status date < max slicer date? 

@ben-t , if date table is not joined

 

new measure =
var _date = MAXX(allselected('Date Table'), 'Date Table'[Date])
return
CALCULATE(distinctCOUNT(Locations[locations.location]),FILTER(Locations, Locations[locations.changedate]<= _max))

 

if joined with date on change date

 

new measure =
var _date = MAXX(allselected('Date Table'), 'Date Table'[Date])
return
CALCULATE(distinctCOUNT(Locations[locations.location]),FILTER(all(Date Table'), 'Date Table'[Date]<= _max))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.

Top Solution Authors