Forum Discussion
Trend calculation dynamically
I have this model :
I have the following measure :
I want to alculate the Trend %. The trend % is calculated by comparing the Last N weeks with the N weeks prior to the Last N weeks Covid cases. For example, if week # 8 & week 9 are the Last N Weeks then it should be compared with the week # 6 & week # 7 dynamically.
Hi, amirabedhiafi
According to your description, I think you can create another measure to display ‘the N weeks prior to the Last N weeks’, so you can use one slicer to get data from two different time periods.
Like this:
Last2NWeeks-LastNWeeks = VAR LastNWeeks = CALCULATE ( SUM ( 'COVID Data'[COVID Cases] ), FILTER ( ALL ( 'Date' ), 'Date'[Week Rank] >= MAX ( 'Date'[Week Rank] ) - WeekRank[WeekRank Value] && 'Date'[Week Rank] <= MAX ( 'Date'[Week Rank] ) ) ) VAR Last2NWeeks = CALCULATE ( SUM ( 'COVID Data'[COVID Cases] ), FILTER ( ALL ( 'Date' ), 'Date'[Week Rank] >= MAX ( 'Date'[Week Rank] ) - WeekRank[WeekRank Value] * 2 && 'Date'[Week Rank] <= MAX ( 'Date'[Week Rank] ) ) ) RETURN Last2NWeeks - LastNWeeksIf it doesn’t solve your problem, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- AnonymousNot applicable
I'd suggest you to use relative date slicer to select last N months to display corresponding records.
Use a relative date slicer and filter in Power BI Desktop
However, Check the following link about dynamic last n month based on slicer.
Display Last N Months & Selected Month using Single Date Dimension in Power BI
- v-janeyg-msftCommunity Support
Hi, amirabedhiafi
According to your description, I think you can create another measure to display ‘the N weeks prior to the Last N weeks’, so you can use one slicer to get data from two different time periods.
Like this:
Last2NWeeks-LastNWeeks = VAR LastNWeeks = CALCULATE ( SUM ( 'COVID Data'[COVID Cases] ), FILTER ( ALL ( 'Date' ), 'Date'[Week Rank] >= MAX ( 'Date'[Week Rank] ) - WeekRank[WeekRank Value] && 'Date'[Week Rank] <= MAX ( 'Date'[Week Rank] ) ) ) VAR Last2NWeeks = CALCULATE ( SUM ( 'COVID Data'[COVID Cases] ), FILTER ( ALL ( 'Date' ), 'Date'[Week Rank] >= MAX ( 'Date'[Week Rank] ) - WeekRank[WeekRank Value] * 2 && 'Date'[Week Rank] <= MAX ( 'Date'[Week Rank] ) ) ) RETURN Last2NWeeks - LastNWeeksIf it doesn’t solve your problem, please feel free to ask me.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.