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
Beerlover
Frequent Visitor

How to calculate last year Rolling 4 weeks

Rolling 4 weeks Sales =
VAR Weeks =
    DATESBETWEEN (
        'Date'[Date],
        MAX ( 'Date'[Date] ) -21,
        MAX ( 'Date'[Date] )
    )
VAR Result =
    CALCULATE ( [Sales], Weeks)
RETURN
    Result
How do i calculate last year rolling 4 weeks?(same time last year based on date selection)
@Greg_Deckler @Uzi2019 
3 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

DATESBETWEEN (
        'Date'[Date],
        MAX ( 'Date'[Date] ) -21-364,
        MAX ( 'Date'[Date] -364)
    )

View solution in original post

Anonymous
Not applicable

 

Rolling 4 Weeks Sales Previous Year =
VAR SelectedDate = MAX ( 'Date'[Date] )
VAR SameDateLastYear = EDATE(SelectedDate, -12)
VAR WeeksLastYear =
    DATESBETWEEN (
        'Date'[Date],
        SameDateLastYear - 21,
        SameDateLastYear
    )
VAR Result =
    CALCULATE ( [Sales], WeeksLastYear)
RETURN
    Result

 

 

I would try this. Then, whenever you set a date (e.g., via a date slicer or on a visual), it does the following:

Sets that as the new max of the date table for the selected context

The second variable determines the same date in the previous year based on the selected value

Then we have dates between SameDateLastYear and the 21 preceding. Then we're calculating Sales based on that. 

Both mine and lbendlin's solution above are similar, but lbendlin's solution always looks at a fixed period (385 - 364 days ago) while solution above looks at 4 week period ending on the same date in the previous year. Could lead to different results if factoring in leap years. 

View solution in original post

Greg_Deckler
Community Champion
Community Champion

@Beerlover Better Rolling Average - Microsoft Fabric Community

 

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

DAX TI measures are the devil. Don't use them. Friendly advice.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Thank you @Greg_Deckler , @lbendlin  and @Anonymous  for your prompt replies.

Hi @Beerlover  ,
May I ask if you have tried the suggestions above? If the suggestion helped you, you might consider marking it as a solution. If the problem has not yet been solved, please feel free to ask us a question.

How to Get Your Question Answered Quickly - Microsoft Fabric Community

If it does not help, please provide more details with your desired out put and pbix file without privacy information.

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Beerlover
Frequent Visitor

Thank you everyone for the response. I am checking it now and will respond soon.

Greg_Deckler
Community Champion
Community Champion

@Beerlover Better Rolling Average - Microsoft Fabric Community

 

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

DAX TI measures are the devil. Don't use them. Friendly advice.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

 

Rolling 4 Weeks Sales Previous Year =
VAR SelectedDate = MAX ( 'Date'[Date] )
VAR SameDateLastYear = EDATE(SelectedDate, -12)
VAR WeeksLastYear =
    DATESBETWEEN (
        'Date'[Date],
        SameDateLastYear - 21,
        SameDateLastYear
    )
VAR Result =
    CALCULATE ( [Sales], WeeksLastYear)
RETURN
    Result

 

 

I would try this. Then, whenever you set a date (e.g., via a date slicer or on a visual), it does the following:

Sets that as the new max of the date table for the selected context

The second variable determines the same date in the previous year based on the selected value

Then we have dates between SameDateLastYear and the 21 preceding. Then we're calculating Sales based on that. 

Both mine and lbendlin's solution above are similar, but lbendlin's solution always looks at a fixed period (385 - 364 days ago) while solution above looks at 4 week period ending on the same date in the previous year. Could lead to different results if factoring in leap years. 

R4W_1 =
VAR SelectedDate = MAX ( 'Date'[Week] )
VAR SameDateLastYear = EDATE(SelectedDate, -12)
VAR WeeksLastYear =
    DATESBETWEEN (
        'Date'[Week],
        SameDateLastYear - 21,
        SameDateLastYear
    )
VAR Result =
    CALCULATE ( [Other Sales Volume], WeeksLastYear)
RETURN
    Result


Week column has Date saved in mm/dd/yyyy

The result is coming as Blank

If you want to compare like for like you need to go with 364 (which will work regardless of leap years).  SAMEPERIODLASTYEAR  will have a weekday shift.

lbendlin
Super User
Super User

DATESBETWEEN (
        'Date'[Date],
        MAX ( 'Date'[Date] ) -21-364,
        MAX ( 'Date'[Date] -364)
    )

Beerlover_0-1715088507101.png

Week column has Date saved in mm/dd/yyyy

You have a misplaced closing parenthesis in row 4.

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.