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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

DAX measure to calculate previous 4 week number considering year change

Hello

 

I am trying to calculate and show a range of week numbers in a Power BI card visualization but the problem is that with the year change (week 52 going forwards to week 1) i want to always show the previous week number and the previous 4 weeks number. For example, it is currently week number 50. I want to show the range week number 46-49 in the card visualization. In 2022, if it is week 2, then the range should show: 50-1.

 

So, here is what i have done for the previous week number:

 

 

PreviousWeekNumber = WEEKNUM(TODAY(),21) - 1

 

 

And to find the previous 4 weeks number:

 

 

3 Weeks Before Previous Week Number = 
return IF([PreviousWeekNumber] == 1, 49, [PreviousWeekNumber]-3)
IF[PreviousWeekNumber] == 2, 50, [PreviousWeekNumber]-3)
IF([PreviousWeekNumber] == 3, 51, [PreviousWeekNumber]-3)
IF([PreviousWeekNumber] == 4, 52, [PreviousWeekNumber]-3)

 

 

But the latter is not working. I am new to Power BI. Any help is much appreciated!!

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

You can rewrite your 3 Weeks expression with a SWITCH:

3 Weeks Before Previous Week Number =
VAR W = [PreviousWeekNumber]
RETURN
    SWITCH (
        W,
        1, 49,
        2, 50,
        3, 51,
        4, 52,
        W - 3
    )

 

Personally, I'd try using modular arithmetic:

3 Weeks Before Previous Week Number =
MOD ( WEEKNUM ( TODAY (), 21 ) - 5, 52 ) + 1

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

You can rewrite your 3 Weeks expression with a SWITCH:

3 Weeks Before Previous Week Number =
VAR W = [PreviousWeekNumber]
RETURN
    SWITCH (
        W,
        1, 49,
        2, 50,
        3, 51,
        4, 52,
        W - 3
    )

 

Personally, I'd try using modular arithmetic:

3 Weeks Before Previous Week Number =
MOD ( WEEKNUM ( TODAY (), 21 ) - 5, 52 ) + 1

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors