The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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!!
Solved! Go to Solution.
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
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