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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
kbell6931
Frequent Visitor

Max Date Function for Date/Time

When I run this DAX query, it functions almost perfectly.  I say almost because it works on date only, but i need it to work with the time that is in the date field as well.

This works

Previous Admission Date = if([CensusType] = 4,
VAR CurrentPatientNo = 'Table1'[PatientID]
VAR CurrentDischargeDate = 'Table1'[DateTime].[Date]
VAR PreviousAdmissionDate =
CALCULATE (
MAX( 'Table1'[ACH/CAH/APH Discharge Date].[Date] ),
FILTER (
'Table1',
'Table1'[ACH/CAH/APH Discharge Date].[Date] < CurrentDischargeDate
&& 'Table1'[PatientID] = CurrentPatientNo
)
)
RETURN
PreviousAdmissionDate)
 
But when i remove the .[Date] from each of the dates, so i can include time as well, it times out and will not complete the query.  it says not enough memory
This does not work for me.

 

Previous Admission Date = if([CensusType] = 4,
VAR CurrentPatientNo = 'Table1'[PatientID]
VAR CurrentDischargeDate = 'Table1'[DateTime]
VAR PreviousAdmissionDate =
CALCULATE (
MAX( 'Table1'[ACH/CAH/APH Discharge Date] ),
FILTER (
'Table1',
'Table1'[ACH/CAH/APH Discharge Date] < CurrentDischargeDate
&& 'Table1'[PatientID] = CurrentPatientNo
)
)
RETURN
PreviousAdmissionDate)
 
 
Any helpful thoughts would be greatly appreciated.  Thanks
1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

@kbell6931 ,

 

If you remove .[date], the loop number will be very large which may cause memory exceeding. You should modify your model structure or reduce the date table rows. You can refer to the doc and blogs below about how to improve the performance:

Optimization guide for Power BI 

A comprehensive guide to Power BI performance tuning

 

Community Support Team _ Jimmy Tao

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

4 REPLIES 4
v-yuta-msft
Community Support
Community Support

@kbell6931 ,

 

If you remove .[date], the loop number will be very large which may cause memory exceeding. You should modify your model structure or reduce the date table rows. You can refer to the doc and blogs below about how to improve the performance:

Optimization guide for Power BI 

A comprehensive guide to Power BI performance tuning

 

Community Support Team _ Jimmy Tao

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

Thank you for your response.  I reduced some of the rows and tweaked a couple optimization points and the query, although still a little slow, worked just as intended.

Greg_Deckler
Community Champion
Community Champion

Ditch your .[Date] 's


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

When I ditch the .[Date]'s it stops working completely.  After some time, it returns an error that there isn't enough memory to perform that function.

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.