cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors