Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
CMSGuy
Helper III
Helper III

Top 6 rolling weekly date sorted by most recent

I have a chart that has a total number of "incidents" and is stacked by type.  The manager wants to see this sorted by week number, but also wants to see the past six weeks.  Can someone direct me on what I need to do here?  Thanks

 

Screenshot 2023-08-30 073154.jpg

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@CMSGuy ,

make sure you have column Year Week or week start date in your table and create a rank on that

 

Have these new columns in Date Table, Week Rank is Important in Date/Week Table
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
WeekDay = weekday([Date],2)
Have these new columns in Date Table, Week Rank is Important in Date/Week Table

Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX('Date','Date'[Year Week],,ASC,Dense) //YYYYWW format

 

 

Then you can have measure like

 

Last 6 weeks =
var _max = maxx(allselected(Date), Date[Week Rank]) // Or// Maxx(filter(Date, Date[Date] = Today()), Date[Week Rank])
var _min = _max -5
return
calculate([Meausre], filter(Date, 'Date'[Week Rank] >=_min && 'Date'[Week Rank] <=_max))

 

 

This measure will work with not filter or when you have range greater than 6 week .

In comment check code for today 

 

If you want to select a date and then want 6 week refer

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@CMSGuy ,

make sure you have column Year Week or week start date in your table and create a rank on that

 

Have these new columns in Date Table, Week Rank is Important in Date/Week Table
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
WeekDay = weekday([Date],2)
Have these new columns in Date Table, Week Rank is Important in Date/Week Table

Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX('Date','Date'[Year Week],,ASC,Dense) //YYYYWW format

 

 

Then you can have measure like

 

Last 6 weeks =
var _max = maxx(allselected(Date), Date[Week Rank]) // Or// Maxx(filter(Date, Date[Date] = Today()), Date[Week Rank])
var _min = _max -5
return
calculate([Meausre], filter(Date, 'Date'[Week Rank] >=_min && 'Date'[Week Rank] <=_max))

 

 

This measure will work with not filter or when you have range greater than 6 week .

In comment check code for today 

 

If you want to select a date and then want 6 week refer

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

For this part, what is [Measure]?

 

return
calculate([Meausre], filter(Date, 'Date'[Week Rank] >=_min && 'Date'[Week Rank] <=_max))

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

August Carousel

Fabric Community Update - August 2024

Find out what's new and trending in the Fabric Community.