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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
amirabedhiafi
Impactful Individual
Impactful Individual

get the last N weeks data

I have the following model : 

 

Capture3.PNG

 

I want to calculate using DAX the Last N Weeks Covid cases excluding the current week. The numbers should change dynamically with the What-if-Parameters selection. The parameter starting from 2 and increasing incrementally by 1 till 28 weeks.

This is my expected output :

Capture1.PNG

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@amirabedhiafi , Refer my post on WOW, You can create Week Rank in You date table and Use that.

 

Last 2  weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-2 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

The above two can come from what if measure

 

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

 

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

5 REPLIES 5
Deepanshi_Ranka
Regular Visitor

Hi @amirabedhiafi ,

Were you able to link this to parameter? Can you share your solution?

 

Thanks.

amitchandak
Super User
Super User

@amirabedhiafi , Refer my post on WOW, You can create Week Rank in You date table and Use that.

 

Last 2  weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-2 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

The above two can come from what if measure

 

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

 

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

How do you get week rank once you have WeekEND Date established in your date table?

@amitchandak I modified it to : 

Last2weeks = 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])))
after creating the Week Rank Calculated Column in the Dimension Date.
But I can't see the value : 
Capture.PNG
Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini

How can I link Last 2  weeks  to the parameter?

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.