cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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

3 REPLIES 3
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)))

Frequent Visitor

hi @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..
Super User

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

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

#### Power BI Monthly Update - June 2024

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

#### New forum boards available in Real-Time Intelligence.

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

Top Solution Authors
Top Kudoed Authors