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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
alexjaco
Frequent Visitor

Previous Week Calculation

Hi, 

 

I am trying to compare each weeks collection amounts to the previous week. I have the following formula:

 

Last weeks Collections Measure =
VAR CurrentWeek = SELECTEDVALUE(Collections[Week Number])
Var CurrentYear = SELECTEDVALUE(Collections[Year])
Var MaxWeekNumber = CALCULATE(MAX(Collections[Week Number]),ALL(Collections))
Return
CALCULATE(SUM(Collections[Weekly Collections]),
Filter(ALL(Collections),
IF(CurrentWeek=1,
Collections[Week Number] = MaxWeekNumber && Collections[Year]=CurrentYear-1,
Collections[Week Number] = CurrentWeek-1 && Collections[Year]=CurrentYear)))
 
When viewing as a table at the date level it works. See below:
 

PowerBi_Help.PNG
 
 
 
 
 
 
However, when other categories are added in, the DAX formula stays filtered at the date level. See below for an example. I've tried swithcing the "CALCULATE" to a "SUMX" but I get the same results. Thank you in advance for your help!
 
PowerBi_Help2.PNG
2 REPLIES 2
amitchandak
Super User
Super User

@alexjaco , refer my blog on Week/WTD. I have used week rank to get this done

https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

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
Anonymous
Not applicable

Hi @alexjaco ,

 

Try the measure as below:

 

Last weeks Collections Measure = 
VAR CurrentWeek = SELECTEDVALUE(Collections[Week Number])
Var CurrentYear = SELECTEDVALUE(Collections[Year])
Var MaxWeekNumber = CALCULATE(MAX(Collections[Week Number]),ALL(Collections))
Return
CALCULATE(SUM(Collections[Weekly Collections]),
Filter(ALL(Collections),[State]=MAX([State])&&
IF(CurrentWeek=1,
Collections[Week Number] = MaxWeekNumber && Collections[Year]=CurrentYear-1,
Collections[Week Number] = CurrentWeek-1 && Collections[Year]=CurrentYear)))

 

If the above doesnt work,pls upload your .pbix file to onedrive business and share the link with us.Do remember to remove the confidential information.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

 

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.