Forum Discussion
Filter last x Weeks
Hi,
I want to bring the last 6 weeks data in my trend chart.
I tried the relative date but unable to get weeks in Date attribute.
Actually i'm calculating week in text form from the date I'm calculating week like;
in current week, we have saturday on 19th December so my week name is like WE 19 Dec 2020 and for sorting these weeks i'm using WeekNumber.
Suggest me a solution how i can i get the last 6 weeks for selected months.
Thanks,
Gaurav
Hi Anonymous ,
Try this:
1. Create a What-if parameter.
2. Create a measure and put it into "Filters on this visual" field of your table visual, and then set as "is not blank".
Last n weeks = VAR n_ = [N Value] VAR MaxWeek = CALCULATE ( MAX ( Dates[Week_Sorting] ), ALLSELECTED ( Dates ) ) VAR ThisWeek_ = MAX ( Dates[Week_Sorting] ) RETURN IF ( ThisWeek_ > MaxWeek - n_ && ThisWeek_ <= MaxWeek, 1 )Best regards
Icey
If this post helps, then consider Accepting it as the solution to help other members find it faster.
4 Replies
- Greg_Deckler
Community Champion
Anonymous - So a lot of times how you do this is to create a calculated column in your table that basically is WEEKNUM(TODAY()) - WEEKNUM([Date]) and then you can filter by the current year and this column <=6
- AnonymousNot applicable
Hi Greg_Deckler
I'm also providing a month filter here. So if user select Month Jun and Jul today(in Dec) so i want to filter last 6 weeks(4 from Jul and last 2 from Jun).
Thanks
Gaurav- Greg_Deckler
Community Champion
Anonymous - Sounds like you want to do it in a measure then instead of a calculated column.
- Icey
Community Support
Hi Anonymous ,
Try this:
1. Create a What-if parameter.
2. Create a measure and put it into "Filters on this visual" field of your table visual, and then set as "is not blank".
Last n weeks = VAR n_ = [N Value] VAR MaxWeek = CALCULATE ( MAX ( Dates[Week_Sorting] ), ALLSELECTED ( Dates ) ) VAR ThisWeek_ = MAX ( Dates[Week_Sorting] ) RETURN IF ( ThisWeek_ > MaxWeek - n_ && ThisWeek_ <= MaxWeek, 1 )Best regards
Icey
If this post helps, then consider Accepting it as the solution to help other members find it faster.