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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Powerline56
Helper I
Helper I

Rolling 7-Day average calculation.

I am trying to get a rolling 7 day average of a value field.  I seem to be having some issues and need some suggestions.  Thanks for any input.
Current Output:

Powerline56_1-1647920161809.png

 

Current Measures:

 

Load to Store Avg =
 AVERAGEX('Load to Store','Load to Store'[value])

 

Rolling Load to Store Avg =

    AVERAGEX(

        FILTER(ALLSELECTED(Dates[Date]),

            Dates[Date] <= MAX(Dates[Date])),

            [Load to Store Avg]

              )

       

7 Day Avg =

VAR period = 7

VAR the_first_date =

    CALCULATE ( FIRSTDATE ( Dates[Date] ), ALLSELECTED ( Dates[Date] ) )    

VAR last_date =

    LASTDATE ( Dates[Date] )

VAR sum_in_period =

    CALCULATE (

        [Rolling Load to Store Avg],             

          DATESINPERIOD ( Dates[Date], last_date, - period, DAY )  

    )

RETURN

    IF ( last_date - the_first_date >= period - 1, sum_in_period )

 

7 Day Avg V2 =

CALCULATE (

    [Rolling Load to Store Avg] / 7,

    DATESINPERIOD (

        Dates[Date],

        LASTDATE ( Dates[Date] ),

        -7,

        DAY

    ),

    FILTER (

        ALL (Dates[Date] ),

        MAX ( Dates[Date] ) < TODAY ()

    )

)

 

1 ACCEPTED SOLUTION

@Powerline56 , Make sure year, month, and day are coming from date table(in visual)  and date table is marked as date table

 

Try with small change

7 Day Avg V3 =
CALCULATE (
AVERAGEX ( VALUES ( Dates[Date] ), [Rolling Load to Store Avg] ),
DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -7, DAY ),
Dates[Date] < TODAY ()
)
 
Rolling Days Formula: https://youtu.be/cJVj5nhkKBw
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Powerline56 , Try like assume you have measure Rolling Load to Store Avg or the sum measure Rolling Load to Store

Try a new measure like 

 

CALCULATE (

AvergaeX(values(Dates[Date]) , [Rolling Load to Store Avg] ) ,

DATESINPERIOD (
Dates[Date],
LASTDATE ( Dates[Date] ),
-7,
DAY
),
FILTER (Dates, Dates[Date] < TODAY ())
)

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks for the quick reply.  I have created a new measure(7 Day Avg V3) with your dax recommendations.  It seems to be mirroring the "Load to Store Avg" calc.  Any suggestions? 

7 Day Avg V3 =
CALCULATE (
AVERAGEX ( VALUES ( Dates[Date] ), [Rolling Load to Store Avg] ),
DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -7, DAY ),
FILTER ( Dates, Dates[Date] < TODAY () )
)

Rolling Load to Store Avg =
    AVERAGEX(
FILTER(ALLSELECTED(Dates[Date]),
Dates[Date] <= MAX(Dates[Date])),
[Load to Store Avg]
)

Load to Store Avg =
AVERAGEX('Load to Store','Load to Store'[value])
 




Powerline56_0-1647921787954.png

 

@Powerline56 , Make sure year, month, and day are coming from date table(in visual)  and date table is marked as date table

 

Try with small change

7 Day Avg V3 =
CALCULATE (
AVERAGEX ( VALUES ( Dates[Date] ), [Rolling Load to Store Avg] ),
DATESINPERIOD ( Dates[Date], LASTDATE ( Dates[Date] ), -7, DAY ),
Dates[Date] < TODAY ()
)
 
Rolling Days Formula: https://youtu.be/cJVj5nhkKBw
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Great that seems to fix the issue.  I will select this as the solution.  I have one more questions regarding this calc.  I am needing to create a seperate measure that will populate based on you're supplied measure calc.  I'm hoping you can help out with how to add a measure as filter context to a seperate measure?  Below is the "ask".


Process Orders 7 Day Avg =

CALCULATE (

    AVERAGEX (

        VALUES ( 'Process Orders'[Inspection Point Date] ),

        [Rolling Process Orders Avg]

    ),

    DATESINPERIOD (

        'Process Orders'[Inspection Point Date],

        LASTDATE ( 'Process Orders'[Inspection Point Date] ),

        -7,

        DAY

    ),

    'Process Orders'[Inspection Point Date]

        < TODAY ()

)

I am needing to create a calculation that using the structure of the below filter context.  The calc below with work without errors but is the filter context used correctly with this method?  Thanks!

New_Calc =

Switch(

      True(), [Process Orders 7 Day Avg] > 1, 1,

                   [Process Orders 7 Day Avg] >0,5,

                    0

)




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.