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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sirlanceohlott
Advocate III
Advocate III

Previous Week To Date DAX

Good afternoon,

 

I hope you are all doing well and staying healthy.

 

I have a Week To Date Calculation and I'd like to create a Previous Week To Date Calculation; however, I'm lost.

 

Here's the Week To Date Calculation:

Week to Date Reqs = 
var CurrentDate=LASTDATE(Calendar_DIM[Date])
var DayNumberOfWeek=WEEKDAY(LASTDATE(Calendar_DIM[Date]),1)
return
CALCULATE(
    [Requirements],
DATESBETWEEN(
    Calendar_DIM[Date],
DATEADD(
    CurrentDate,
    -1*DayNumberOfWeek,
    DAY),
    CurrentDate))

 

I appreciate your help in advance!

 

Thank you,
Lance M 

1 ACCEPTED SOLUTION

Hi, @sirlanceohlott 

Try measures as below:

Last Week to Date Reqs 2 = 
VAR CurrentDate =
    LASTDATE ( Calendar_DIM[Date] )
VAR DayNumberOfWeek =
    WEEKDAY ( LASTDATE ( Calendar_DIM[Date] ), 1 )
RETURN
    CALCULATE (
        [Requirements],
        FILTER (
            ALL ( Calendar_DIM[Date] ),
            WEEKDAY ( [Date], 1 ) <= DayNumberOfWeek
                && [Date] <= CurrentDate - DayNumberOfWeek &&   [Date] >= CurrentDate - DayNumberOfWeek -7
        )
    )

 

Pbix attached

 

Best Regards,
Community Support Team _ Eason
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

5 REPLIES 5
amitchandak
Super User
Super User

Try Like

Week to Date Reqs = 
var _curr= LASTDATE(Calendar_DIM[Date])
var _min= _curr + (-1*WEEKDAY(_curr)+1) -7
var _max =_curr-7

return
CALCULATE(
    [Requirements],
filter(Calendar_DIM,Calendar_DIM[Date]>=_min && Calendar_DIM[Date]<=_max))

/////////////OR

Week to Date Reqs = 
var _curr= LASTDATE(Calendar_DIM[Date])
var _min= _curr + (-1*WEEKDAY(_curr)+1) -7
var _max =_curr-7

return
CALCULATE(
    [Requirements],
filter(all(Calendar_DIM),Calendar_DIM[Date]>=_min && Calendar_DIM[Date]<=_max))

@amitchandak,

 

I appreciate you reaching out and sharing the DAX you did.

 

When I run the following: 

PREV Week to Date Reqs = 
var _curr= LASTDATE(Calendar_DIM[Date])
var _min= _curr + (-1*WEEKDAY(_curr)+1) -7
var _max =_curr-7

return
CALCULATE(
    [Requirements],
filter(all(Calendar_DIM),Calendar_DIM[Date]>=_min && Calendar_DIM[Date]<=_max))

 

It shows the entire week's worth instead of the previous week to date(Sun-Wed). 

Hi, @sirlanceohlott 

Try measures as below:

Last Week to Date Reqs 2 = 
VAR CurrentDate =
    LASTDATE ( Calendar_DIM[Date] )
VAR DayNumberOfWeek =
    WEEKDAY ( LASTDATE ( Calendar_DIM[Date] ), 1 )
RETURN
    CALCULATE (
        [Requirements],
        FILTER (
            ALL ( Calendar_DIM[Date] ),
            WEEKDAY ( [Date], 1 ) <= DayNumberOfWeek
                && [Date] <= CurrentDate - DayNumberOfWeek &&   [Date] >= CurrentDate - DayNumberOfWeek -7
        )
    )

 

Pbix attached

 

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

Hi, Can you please help with Last Year Week to Date aswell

@v-easonf-msft ,

 

Thank you, this formula works! 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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