Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi,
I'm wanting to display "Last 6 weeks" based on off the week ending, and also display "Last 6 weeks prior period" so that we can compare how the exact same 6 weeks were the year before. I have the following formula, which works for the "Last 6 weeks" but not the "Last 6 weeks prior period".
I'm assuming it's to do with the logic in:
Past 6 Weeks or Prior Period =
IF(
(
'Date'[TodayWeekNum] - 'Date'[Week Number] < 7 &&
'Date'[TodayWeekNum] - 'Date'[Week Number] >= 0 &&
'Date'[Year] = YEAR(TODAY())
),
"Last 6 weeks",
IF(
'Date'[Year] = YEAR(TODAY()) - 1 &&
'Date'[Week Number] >= 52 - (6 - 'Date'[TodayWeekNum]),
"Prior Period Comparison",
"False"
)
)
Can anyone please help out? Thanks!
Solved! Go to Solution.
Thanks for the reply from @lbendlin , please allow me to provide another insight:
Hi @Shawry ,
Here are the steps you can follow:
1. Create calculated column.
Past 6 Weeks or Prior Period =
var _today=TODAY()
var _weektoday=WEEKNUM(_today,2)
var _currentmaxdate=MAXX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(_today)&&'Table'[Week]=_weektoday-1),[Date])
var _currentmindate=MINX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(_today)&&'Table'[Week]=_weektoday-6),[Date])
var _lastmaxdate=MAXX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(_today)-1&&'Table'[Week]=_weektoday-1),[Date])
var _lastmindate=MINX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(_today)-1&&'Table'[Week]=_weektoday-6),[Date])
return
SWITCH(
TRUE(),
'Table'[Date]>=_currentmindate&&'Table'[Date]<=_currentmaxdate,"Last 6 weeks",
'Table'[Date]>=_lastmindate&&'Table'[Date]<=_lastmaxdate,"Last 6 weeks prior period","False")
2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Thanks for the reply from @lbendlin , please allow me to provide another insight:
Hi @Shawry ,
Here are the steps you can follow:
1. Create calculated column.
Past 6 Weeks or Prior Period =
var _today=TODAY()
var _weektoday=WEEKNUM(_today,2)
var _currentmaxdate=MAXX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(_today)&&'Table'[Week]=_weektoday-1),[Date])
var _currentmindate=MINX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(_today)&&'Table'[Week]=_weektoday-6),[Date])
var _lastmaxdate=MAXX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(_today)-1&&'Table'[Week]=_weektoday-1),[Date])
var _lastmindate=MINX(FILTER(ALL('Table'),YEAR('Table'[Date])=YEAR(_today)-1&&'Table'[Week]=_weektoday-6),[Date])
return
SWITCH(
TRUE(),
'Table'[Date]>=_currentmindate&&'Table'[Date]<=_currentmaxdate,"Last 6 weeks",
'Table'[Date]>=_lastmindate&&'Table'[Date]<=_lastmaxdate,"Last 6 weeks prior period","False")
2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
years and weeks are incompatible. If you want to compare like for like you need to use TODAY()-35 to TODAY() for the current period and TODAY-399 to TODAY()-364 for the prior period.
User | Count |
---|---|
25 | |
12 | |
8 | |
8 | |
7 |
User | Count |
---|---|
27 | |
13 | |
13 | |
11 | |
6 |