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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
adlsh11
Frequent Visitor

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

@adlsh11 , 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-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@adlsh11 , 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-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

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

@adlsh11 , 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.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.