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

Measure Help - Previous Week Calculation

Hello,

 

I've reviewed quite a few threads on PW calculations but can't seem to get mine to work.  I've got a single table where I added a custom column to show the week starting date: 
WeekStart = JCCD[ActualDate]- WEEKDAY(JCCD[ActualDate],1)+1

 

I have the following table layout:

1.png

 

An my previous week calculation is:

PWM = CALCULATE([AH], FILTER(ALLSELECTED(JCCD), JCCD[WeekStart] = [mDate]))
mDate = MAX(JCCD[WeekStart]) - 7
 
If I drop mDate into the table, I see the context is correct, but the cal doesn't come out:
2.png
 
What am I doing wrong?
 
Thanks!
1 ACCEPTED SOLUTION
Anonymous
Not applicable

I finally figured it out by doing the following:

 

1. Created a calendar table

2. Changed the column on the matrix from the fact table to the dimension table (calendar)

3. Created the following formula.

    Prior Week =
          CALCULATE(SUM('JCCD'[ActualHours]), Filter(ALL('Calendar'), 'Calendar'[Week Start] = max('Calendar'[Week Start]) - 7))


I was close before, just needed the calendar table for the filtering to work and changing the column as mentioned in #2.  Now it looks like it should.

1.png

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

I finally figured it out by doing the following:

 

1. Created a calendar table

2. Changed the column on the matrix from the fact table to the dimension table (calendar)

3. Created the following formula.

    Prior Week =
          CALCULATE(SUM('JCCD'[ActualHours]), Filter(ALL('Calendar'), 'Calendar'[Week Start] = max('Calendar'[Week Start]) - 7))


I was close before, just needed the calendar table for the filtering to work and changing the column as mentioned in #2.  Now it looks like it should.

1.png

 

amitchandak
Super User
Super User

Create a date table and all your week, month calculation should be there. As long as you are grouping data on week, a 7  days behind measure should also work

 

 

//In date table
Week Start date = DATEADD('Date'[Date],-1*WEEKDAY('Date'[Date])+1,DAY)
Week End date = DATEADD('Date'[Date],7-1*WEEKDAY('Date'[Date]),DAY)

WM(This week) = CALCULATE([AH], FILTER(JCCD, JCCD[ActualDate] <=maxx(date,date[week start date]) && JCCD[ActualDate] >=minx(date,date[week end date])))

PWM = CALCULATE([AH], FILTER(JCCD, JCCD[ActualDate] <=maxx(date,dateadd(date[week start date],-7,day)) && JCCD[ActualDate] >=minx(date,dateadd(date[week end date],-7,DAY))))

PWM (7 day behind)= CALCULATE([AH], dateadd(date[date],-7,DAY))

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

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

Another way but will work on week level

Week Rank = RANKX('Date','Date'[Week Start date],,ASC,Dense)

Measure = CALCULATE([AH], all('Date'),filter('Date','Date'[Week Rank]=max('Date'[Week Rank])-1))
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 Amit,

 

This seems to experience the same issue I encountered:

3.png

 

Here is the file if you want to take a look: Previous Week Calc 

 

Thanks for taking a look!

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.