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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
shippen70
Helper I
Helper I

Direct Query Calculate LastDate issue

I am creating a visual for a Direct Query.  I need to return the LastDate from my Date Dimension table (Rolling Calendar) and pass that into my CALCULATE Function to sum the TotalDrawers for that date.  I keep getting a locking error.  When I check it in DAXStudio it indicated there is an issue with LASTDATE.  Seems that this has to do with the LASTDATE being used in a CALCULATE function on a Direct Query.  Any thoughts on how to resolve the issue?

 

 

 
 

 

 

WTDDrawers =
VAR SelectDate =
LASTDATE( 'Rolling Calendar'[Calendar Date] )
VAR DayNumberOfWeek =
WEEKDAY ( LASTDATE ( 'Rolling Calendar'[Calendar Date] ), 1 )
//VAR TestFirstDate = DATEADD ( SelectDate, ( -1 * DayNumberOfWeek ) + 1, DAY )
RETURN
CALCULATE (
SUM ( _AE1WeekComp[TotalDrawers] ),
DATESBETWEEN (
'Rolling Calendar'[Calendar Date],
DATEADD ( SelectDate, ( -1 * DayNumberOfWeek ), DAY ),
SelectDate
)
)
5 REPLIES 5
amitchandak
Super User
Super User

@shippen70 , Try like

WTDDrawers =
VAR SelectDate =
maxx(allselected('Rolling Calendar'), 'Rolling Calendar'[Calendar Date] )
VAR DayNumberOfWeek =
WEEKDAY ( SelectDate, 1 )
//VAR TestFirstDate = DATEADD ( SelectDate, ( -1 * DayNumberOfWeek ) + 1, DAY )
RETURN
CALCULATE (
SUM ( _AE1WeekComp[TotalDrawers] ),
DATESBETWEEN (
'Rolling Calendar'[Calendar Date],
DATEADD ( SelectDate, ( -1 * DayNumberOfWeek ), DAY ),
SelectDate
)
)

 

I did no check formula logic

 

For week refer

https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

In case you can not add more column to date table in the database have one in power BI

https://youtu.be/24arfrD3Qzk

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
Mariusz
Community Champion
Community Champion

Hi @shippen70 

Try MAX( 'Rolling Calendar'[Calendar Date] )

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

I tried using MAX but then I get the error that is needs a Column Reference.

Hi @shippen70 

 

Is this happening when using MAX( _ ) on its own or only as part of your synatx?

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Alone
MAX( 'Rolling Calendar'[Calendar Date] )

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.