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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
firescape
Frequent Visitor

Date filtering and moving average calculation

I'm using your run of the mill moving average DAX formula and noticed that filtered dates do not get excluded from the calculation

 

7 Day Avg = 
CALCULATE(AVERAGEX (
    DATESINPERIOD (
        'Calendar'[Date],
        LASTDATE ( 'Calendar'[Date] ),
        -7,
        DAY
    ),
    [Staff #]
))

 

I'm assuming the is due to DATESINPERIOD not respecting filters, is there any way to fix that?

 

Filtering on any other column works as expected.

 

2 REPLIES 2
AntrikshSharma
Super User
Super User

@firescape I didn't get the first few words of the first sentence, you should try to write you code like this:

7 Day Avg =
CALCULATE (
    AVERAGEX ( VALUES ( 'Calendar'[Date] ), [Staff #] ),
    DATESINPERIOD ( 'Calendar'[Date], LASTDATE ( 'Calendar'[Date] ), -7, DAY )
)

I have also made a video on moving average, in case if you are interested, then check the first link after my signature.

 

I tried that formula and I'm still having the same issue, see below for an example.

 

Before filtering:

Capture.PNG

 

After filtering out January 11th notice how the average hasn't chaged for January 12th when it should be 175.

Capture2.PNG

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.