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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Week over Week comparison, at the change of the year

The DAX formula belows: 
 
Customers PW =
VAR CurrentWeek = SELECTEDVALUE(DimDate[ISO week])
VAR CurrentYear = SELECTEDVALUE(DimDate[ISO YEAR])
VAR MaxWeekNumber = CALCULATE(MAX(DimDate[ISO week]),ALL(DimDate))

RETURN

SUMX(
FILTER(ALL(DimDate),
IF(CurrentWeek=1,
DimDate[WeekNumber] = MaxWeekNumber && DimDate[ISO YEAR] = CurrentYear-1 ,
DimDate[WeekNumber] = CurrentWeek - 1 && DimDate[ISO YEAR] = CurrentYear)),
appointments[customers])
 
returns the total number of customers on the past week (PW). The formula works fine for the same year. 
However, as this year has turned 2022, the formula does not know that 2021-52 is the week before 2022-01.
How can I adjust the formula above?
Thanks.
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Please create rank on year week column in week or date table and use that

 

example

 

Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format
measures
This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
Last year Week= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -53)))

 

Power BI — Week on Week and WTD
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-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8

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

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Please create rank on year week column in week or date table and use that

 

example

 

Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format
measures
This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
Last year Week= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -53)))

 

Power BI — Week on Week and WTD
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-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Previous Week Numbers Error.pnghi @amitchandak it seems to answer my question. On a similar topic, the result based on formula for LWTD seems to be off though..
From the appointments table, 

Customers LWTD =
CALCULATE(appointments[customers],
FILTER(ALL('DimDate'),'DimDate'[Week Rank]=(max('DimDate'[Week Rank]) -1)
&& 'DimDate'[Weekday] <=max('DimDate'[Weekday])))


seems to result a number for the whole year.
Any idea why that may be the case?

As comparison, this is the formula I use for determining Customers WTD.

Customers WTD = CALCULATE(appointments[customers],
FILTER(ALL('DimDate'),
'DimDate'[Week Rank]=max('DimDate'[Week Rank]) &&
'DimDate'[Weekday] <=max('DimDate'[Weekday])))

Customers WTD returns 43, whereas Customers PWTD returns 15.509..

@Anonymous , Hope this a measure, not a column, use of appointments[customers] creating a doubt.

if customers is a measure, then below should work with a datetable, marked as a date table

 

Customers LWTD =
CALCULATE([customers],
FILTER(ALL('DimDate'),'DimDate'[Week Rank]=(max('DimDate'[Week Rank]) -1)
&& 'DimDate'[Weekday] <=max('DimDate'[Weekday])))

 

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors