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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Moving Average - 7 day

Hi all,

 

I have a DAX formula which helps me calculating a 7 day moving average, as follows:

 

Rolling AVG - 7 days = CALCULATE(SUM(val_summary_by_day_source_tv_region[vals_booked])/7,DATESINPERIOD('Calendar Reference'[Date_2],LASTDATE('Calendar Reference'[Date_2]),-7, DAY),ALLEXCEPT(val_source_ref_lookup,val_source_ref_lookup[val_business_category]))
 
The issue I'm having is that it calculates 7 days into the future, how can I edit the formula to only calculate up to yesterday?
 
Many thanks,
 
Jason
1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

hi, @Anonymous

You could add a conditional in your formula as below:

Rolling AVG - 7 days =
CALCULATE (
    SUM ( val_summary_by_day_source_tv_region[vals_booked] ) / 7,
    DATESINPERIOD (
        'Calendar Reference'[Date_2],
        LASTDATE ( 'Calendar Reference'[Date_2] ),
        -7,
        DAY
    ),
    ALLEXCEPT (
        val_source_ref_lookup,
        val_source_ref_lookup[val_business_category]
    ),
    FILTER (
        ALL ( 'Calendar Reference' ),
        MAX ( 'Calendar Reference'[Date_2] ) < TODAY ()
    )
)

Result:

BeforeBeforeAfterAfter

 

Best Regards,

Lin

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

View solution in original post

2 REPLIES 2
v-lili6-msft
Community Support
Community Support

hi, @Anonymous

You could add a conditional in your formula as below:

Rolling AVG - 7 days =
CALCULATE (
    SUM ( val_summary_by_day_source_tv_region[vals_booked] ) / 7,
    DATESINPERIOD (
        'Calendar Reference'[Date_2],
        LASTDATE ( 'Calendar Reference'[Date_2] ),
        -7,
        DAY
    ),
    ALLEXCEPT (
        val_source_ref_lookup,
        val_source_ref_lookup[val_business_category]
    ),
    FILTER (
        ALL ( 'Calendar Reference' ),
        MAX ( 'Calendar Reference'[Date_2] ) < TODAY ()
    )
)

Result:

BeforeBeforeAfterAfter

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
AlB
Super User
Super User

Hi @Anonymous

Can you show how/where you are using the measure? I mean, is it on a matrix visual? If so, what are you placing in the rows of the matrix?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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