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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Week to date this week compared to week to date prior Week

Hi everyone, 

I need to calculate the number of units sold this week to date in one measure and with a 2nd measure compare it to the prior week to date, such that units from Sunday through Friday of this week are compared with units from Sunday through Friday of last week. I've worked out units week to date this week below, also worked out units prior *full* week (Sunday through Monday) however *week to date" prior week (as opposed to full week) evades me. Thanks in advance for any ideas:

 

Measures:

 

Units WTD =
VAR CurrentDate = LASTDATE ( 'Date'[CalendarDate] )
VAR DayNumberOfWeek = WEEKDAY ( LASTDATE ( 'Date'[CalendarDate] ), 3 )

 

RETURN
CALCULATE (SUM ( Orders[Units] ),
DATESBETWEEN ('Date'[CalendarDate],DATEADD ( CurrentDate, -1 * DayNumberOfWeek, DAY ),CurrentDate))


Units Prior Full Week =
VAR CurrentWeek = SELECTEDVALUE('Date'[WeekNo])
VAR CurrentYear = SELECTEDVALUE('Date'[Year])
VAR MaxWeekNumber = CALCULATE(MAX('Date'[WeekNo]), ALL('Date'))

RETURN
SUMX(FILTER(ALL('DATE'),IF(CurrentWeek = 1,'Date'[WeekNo] = MaxWeekNumber && 'Date'[Year] = CurrentYear - 1,
'Date'[WeekNo] = CurrentWeek - 1 && 'Date'[Year] = CurrentYear )),
[Units]) 

 

Seems like it should be something like this:

 

Units WTD Prior Week =
VAR CurrentDate = LASTDATE('Date'[CalendarDate])
VAR DayNumberOfWeek = WEEKDAY(LASTDATE('Date'[CalendarDate]),3)
VAR CurrentWeek = SELECTEDVALUE('Date'[WeekNo])
VAR CurrentYear = SELECTEDVALUE('Date'[Year])
VAR MaxWeekNumber = CALCULATE(MAX('Date'[WeekNo]), ALL('Date'))

RETURN
SUMX(
FILTER(ALL('Date'), AND(
IF(CurrentWeek = 1,
'Date'[WeekNo] = MaxWeekNumber && 'Date'[Year] = CurrentYear - 1,
'Date'[WeekNo] = CurrentWeek - 1 && 'Date'[Year] = CurrentYear ), DATESBETWEEN('Date'[CalendarDate],DATEADD(CurrentDate,-1*DayNumberOfWeek,DAY),CurrentDate))),
[Units])

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I came up with the following solution:

 

Revenue WTD =
VAR CurrentDate=LASTDATE('Date'[CalendarDate])
VAR DayNumberOfWeek=WEEKDAY(LASTDATE('Date'[CalendarDate]),3)
RETURN
CALCULATE(SUM(Orders[total_price]),DATESBETWEEN('Date'[CalendarDate],DATEADD(CurrentDate, DayNumberOfWeek * -1, DAY),CurrentDate))

 

Revenue WTD Prior Week =
VAR CurrentDate=LASTDATE('Date'[CalendarDate])
VAR PriorWeekDate=DATEADD(CurrentDate,-7,DAY)
VAR DayNumberOfWeek=WEEKDAY(LASTDATE('Date'[CalendarDate]),3)
RETURN
CALCULATE(SUM(Orders[total_price]),DATESBETWEEN('Date'[CalendarDate],DATEADD(PriorWeekDate, DayNumberOfWeek * -1, DAY), PriorWeekDate))

View solution in original post

2 REPLIES 2
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous

 

Here are some references for you. If it is not your case, please share a simplified data sample and expected output.

https://community.powerbi.com/t5/Desktop/Last-Week-Previous-Week-Calculation-Formula-Review/td-p/218653

https://community.powerbi.com/t5/Desktop/Week-over-Week/td-p/379226

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

I came up with the following solution:

 

Revenue WTD =
VAR CurrentDate=LASTDATE('Date'[CalendarDate])
VAR DayNumberOfWeek=WEEKDAY(LASTDATE('Date'[CalendarDate]),3)
RETURN
CALCULATE(SUM(Orders[total_price]),DATESBETWEEN('Date'[CalendarDate],DATEADD(CurrentDate, DayNumberOfWeek * -1, DAY),CurrentDate))

 

Revenue WTD Prior Week =
VAR CurrentDate=LASTDATE('Date'[CalendarDate])
VAR PriorWeekDate=DATEADD(CurrentDate,-7,DAY)
VAR DayNumberOfWeek=WEEKDAY(LASTDATE('Date'[CalendarDate]),3)
RETURN
CALCULATE(SUM(Orders[total_price]),DATESBETWEEN('Date'[CalendarDate],DATEADD(PriorWeekDate, DayNumberOfWeek * -1, DAY), PriorWeekDate))

Helpful resources

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

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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