Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.