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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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