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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

For this part, what is [Measure]?

 

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.