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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Quest77
New Member

4 / 13/ 52 Week Rolling Averages

Hi I am trying to create a number of cards that contain the following rolling averages. 4 week, 13 week and 52 week. I don't know what measure to create in order to achieve these reults. I can try and send the sample file but not sure best way to attach it. 

Link to sample file attached

 

https://1drv.ms/u/s!AiZ1-kl9lagZgt4olcKdIRRuzIxiEg?e=bbrnvL

 

 

Data Table

Quest77_3-1671903114098.png

Calendar Table

Quest77_2-1671903091983.png

Visual I am trying to achieve for weekly averages

Quest77_1-1671903061375.png

Weekly Sum Matrix already built

Quest77_0-1671903022666.png

 

1 ACCEPTED SOLUTION
AlB
Super User
Super User

@Quest77 

See it all at work in the attached file (Overview page)

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

7 REPLIES 7
AlB
Super User
Super User

@Quest77 

See it all at work in the attached file (Overview page)

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

When i used the same function to create measure current week offset, it got failed due to an error that a single value cannot be determined. Anyway i can connect with you about this problem? Thank you very much.

AlB
Super User
Super User

@Quest77 

Exactly same pattern for the 13 and 52 week. Only the variable at the top changes 

13 Week Rolling Average = 
VAR numWeeks_ = 13
VAR weeksT_ =
    CALCULATETABLE (
        DISTINCT ( 'Calendar'[CurrentWeekOffset] ),
        'Calendar'[CurrentWeekOffset] >= - numWeeks_,
        'Calendar'[CurrentWeekOffset] <= 0,
        ALL ( 'Calendar' )
    )
RETURN
    CALCULATE (
        AVERAGEX ( weeksT_, CALCULATE ( SUM ( SETTLEMENT_STATEMENTS[Sales] ) ) ),
        ALL ( 'Calendar' )
    )

 

52 Week Rolling Average = 
VAR numWeeks_ = 52
VAR weeksT_ =
    CALCULATETABLE (
        DISTINCT ( 'Calendar'[CurrentWeekOffset] ),
        'Calendar'[CurrentWeekOffset] >= - numWeeks_,
        'Calendar'[CurrentWeekOffset] <= 0,
        ALL ( 'Calendar' )
    )
RETURN
    CALCULATE (
        AVERAGEX ( weeksT_, CALCULATE ( SUM ( SETTLEMENT_STATEMENTS[Sales] ) ) ),
        ALL ( 'Calendar' )
    )

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

AlB
Super User
Super User

@Quest77 

First create a calculated column with the number of weeks offset from the current week for each date in the Calendar table. This will simplify the measures:

CurrentWeekOffset = 
VAR currentWeekStart_ =
    DATEVALUE (
        LOOKUPVALUE ( 'Calendar'[Week Start Date], 'Calendar'[Date], TODAY () )
    )
VAR currentRowWeekStart_ = 'Calendar'[Week Start Date]
RETURN
    DATEDIFF ( currentWeekStart_, currentRowWeekStart_, WEEK )

 

Then build the measure for the 4 week rolling average. Note it is going back from the current date

4 Week Rolling Average V2 = 
VAR numWeeks_ = 4
VAR weeksT_ =
    CALCULATETABLE (
        DISTINCT ( 'Calendar'[CurrentWeekOffset] ),
        'Calendar'[CurrentWeekOffset] >= - numWeeks_,
        'Calendar'[CurrentWeekOffset] <= 0,
        ALL ( 'Calendar' )
    )
RETURN
    CALCULATE (
        AVERAGEX ( weeksT_, CALCULATE ( SUM ( SETTLEMENT_STATEMENTS[Sales] ) ) ),
        ALL ( 'Calendar' )
    )

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

If my date table already has week start date, do we still need calendarweekoffset? When i tried to create the first measure, it didn't work.

AlB
Super User
Super User

Hi @Quest77 

You have to share the URL to the file hosted elsewhere: Dropbox, Onedrive... or just upload the file to a site like tinyupload.com (no sign-up required).


SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

I attached the sample file via link in my original post

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.