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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
AppleBoy
Regular Visitor

DAX Measure for Rolling 3-Month Average Not Working as Expected

I’m trying to calculate a rolling 3-month average of a calculated column Working_Hours in Power BI. The logic should behave like Excel’s moving average:

For the first few months, it should return a cumulative average until 3 months of data are available.
From the 4th month onward, it should return a rolling average of the previous three months for example
For April - It should consider Jan feb and march
For may Feb, march and Aprile.
I’ve created a Metric Month column using EOMONTH([Closed_date], 0) and a calculated column Working_Hours that excludes weekends using a Calendar table.

However, the DAX measure I’ve written is returning incorrect values — either the same value across all months or inflated numbers that don’t match the expected logic.

I’ve tried using DATESINPERIOD, FILTER, and CALCULATE with AVERAGE, but the measure doesn’t respect the month context correctly.

I’ve also ensured that the Calendar table is related to the Metric Month column.

Could you please help me with the correct DAX measure or advise on how to structure this calculation properly?

1 ACCEPTED SOLUTION
v-tsaipranay
Community Support
Community Support

Hi @AppleBoy ,

Thanks for reaching out to the Microsoft fabric community forum.

 

I have used this measure-

measure =

CALCULATE(

    AVERAGEX(

        demands_sample,demands_sample[Working Hours]),

    DATESINPERIOD(demands_sample[Closed],

        MAX(demands_sample[Closed]),

        -3,

        MONTH

    )

)

This should ideally work for rolling averages.

Turns out, the sample data provided was not proper. Ideally the closed date which you are referring here, should not have duplicate values. Since it has , this is not working.
For your reference, please take a look at the similar thread that has already been accepted.
Solved: Rolling average last 3 months - Microsoft Fabric Community
Solved: Re: Rolling 3 months not working properly - Microsoft Fabric Community

Hope this helps. Please feel free to rech out for any further questions.


Thank you .




View solution in original post

9 REPLIES 9
v-tsaipranay
Community Support
Community Support

Hi @AppleBoy ,

 

We haven’t received an update from you in some time. Could you please let us know if the issue has been resolved?
If you still require support, please let us know, we are happy to assist you.

 

Thank you.

v-tsaipranay
Community Support
Community Support

Hi @AppleBoy ,

 

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. 

 

Thank you.

v-tsaipranay
Community Support
Community Support

Hi @AppleBoy ,

 

I wanted to follow up on our previous suggestions. We would like to hear back from you to ensure we can assist you further.

 

Thank you.

v-tsaipranay
Community Support
Community Support

Hi @AppleBoy ,

Thanks for reaching out to the Microsoft fabric community forum.

 

I have used this measure-

measure =

CALCULATE(

    AVERAGEX(

        demands_sample,demands_sample[Working Hours]),

    DATESINPERIOD(demands_sample[Closed],

        MAX(demands_sample[Closed]),

        -3,

        MONTH

    )

)

This should ideally work for rolling averages.

Turns out, the sample data provided was not proper. Ideally the closed date which you are referring here, should not have duplicate values. Since it has , this is not working.
For your reference, please take a look at the similar thread that has already been accepted.
Solved: Rolling average last 3 months - Microsoft Fabric Community
Solved: Re: Rolling 3 months not working properly - Microsoft Fabric Community

Hope this helps. Please feel free to rech out for any further questions.


Thank you .




AppleBoy
Regular Visitor

AppleBoy_0-1758290392846.png

It doesnt work. It is result in the avg of working hrs. 

The goal is to get the avg of the jan feb and march in the moth on april 

 

Please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Alternatively, you can share your .pbix via some cloud service and paste the link here. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.

 

Need help uploading data? click here

 

AppleBoy_1-1758524272510.png

 

Sample Data (First 8 Rows)

Number

Name

Opportunity Id

State

Portfolio

Demand manager

Client name

City

Country

Project

Start Date

Opened

Date Of Demand Created

Closed

Deferred reason

Order type

Date Of Project Created

Created by

State.1

Time

Working Hours

Region

Status

T1DMD0078705

US - Akamai Technologies, Inc - Switch to WC API

6053098.0

Deferred

WorldCheck

Roy Taylor

Akamai Technologies, Inc

Cambridge

United States

nan

2025-05-30 00:00:00

2025-05-30 23:31:50

2025-05-30 23:31:50

2025-06-02 19:46:38

Products/Service Out of Scope

Pilot

NaT

nan

nan

-1099391.5305555556

0.0

AMERS

Pending

T1DMD0078690

Starter - Allan Gray Proprietary Limited-EMEA-One API - One API

6401149.0

Completed

WorldCheck

Jean Bruno Kinguenguy

Allan Gray Proprietary Limited

Cape Town

South Africa

Starter - Allan Gray Proprietary Limited-EMEA-One API - One API

2025-05-30 00:00:00

2025-05-30 18:54:39

2025-05-30 18:54:39

2025-05-30 19:46:09

nan

Pilot

2025-05-30 19:46:07

jkinguen

Work in Progress

0.8577777776517905

0.8577777776517905

EMEA

Closed

T1DMD0078663

Starter - PLUS500 LTD-EMEA-One API - One API

6474971.0

Completed

WorldCheck

Himalaya Garg

PLUS500 LTD

Haifa

Israel

Starter - PLUS500 LTD-EMEA-One API - One API

2025-05-30 00:00:00

2025-05-30 12:50:11

2025-05-30 12:50:11

2025-05-30 13:32:31

nan

Pilot

2025-05-30 13:32:29

hgarg

Work in Progress

0.7050000001327135

0.7050000001327135

EMEA

Closed

T1DMD0078621

Grab - DS Work

nan

Completed

WorldCheck

Ray Sun

GP Network Asia Pte. Ltd.

Singapore

Singapore

Grab - DS Work

2025-05-29 00:00:00

2025-05-29 14:11:43

2025-05-29 14:17:48

2025-05-29 14:23:11

nan

nan

2025-05-29 14:23:10

rsun1

Work in Progress

0.08944444439839572

0.08944444439839572

nan

Closed

T1DMD0078598

Starter - Shelf Drilling Holdings, Ltd - Amers - One API - One API

6369707.0

Completed

WorldCheck

Ray Sun

Shelf Drilling Holdings, Ltd

George Town

Cayman Islands

Starter - Shelf Drilling Holdings, Ltd - Amers - One API - One API

2025-05-29 00:00:00

2025-05-29 02:08:52

2025-05-29 02:08:53

2025-05-29 08:10:45

nan

Pilot

2025-05-29 08:10:44

rsun1

Closed Skipped

6.030833333381452

6.030833333381452

AMERS

Closed

T1DMD0078574

Atlas Consolidated Pte Ltd-Asia-One API - One API

6083687.0

Completed

WorldCheck

Vikram M V

Atlas Consolidated Pte Ltd

Singapore

Singapore

Atlas Consolidated Pte Ltd-Asia-One API - One API

2025-05-28 00:00:00

2025-05-28 16:40:10

2025-05-28 16:40:10

2025-05-29 09:28:17

nan

Pilot

2025-05-29 09:28:15

vmv

Pending

16.801388888969086

16.80111111119131

ASIA

Closed

T1DMD0078543

IGT Global Solutions Corporation - Americas - OneAPI - One API

6348389.0

Completed

WorldCheck

Judith Pillado

IGT Global Solutions Corporation

Providence

United States

IGT Global Solutions Corporation - Americas - OneAPI - One API

2025-05-28 00:00:00

2025-05-28 04:14:46

2025-05-28 04:14:46

2025-05-29 07:27:59

nan

Pilot

2025-05-29 07:27:57

jpillado

Pending

27.219722222245764

27.21944444446799

AMERS

Closed

T1DMD0078531

Advanced - Summit Bank -EMEA-One API - One API

6502796.0

Completed

WorldCheck

Jean Bruno Kinguenguy

Summit Bank

Jahi Abuja

Nigeria

Advanced - Summit Bank -EMEA-One API - One API

2025-05-27 00:00:00

2025-05-27 21:13:12

2025-05-27 21:13:12

2025-05-28 13:08:56

nan

Pilot

2025-05-28 13:08:55

jkinguen

Closed Skipped

15.928611111128703

15.928333333350926

EMEA

Closed

Expected Outcome

Attached is sample data, working hrs =LET(StartDay,M18,EndDay,Q18,DayStart,TIME(0,0,0),DayEnd,TIME(23,59,59),
incStart,NETWORKDAYS(StartDay,StartDay),
incEnd,NETWORKDAYS(EndDay,EndDay),

This is what is expected: When avaliable for the previous three month it should calculate for the 4th month 

Data Model Diagram

 

Data model diagram could not be added.

DataNinja777
Super User
Super User

Hi @AppleBoy ,

 

It seems you're encountering a common filter context issue in DAX. To create a rolling 3-month average, you need a measure that can override the visual's context for a single month and apply its own date range. The solution is to use the CALCULATE function in combination with DATESINPERIOD to define this rolling window. This approach will also correctly handle the cumulative average for the first few months of your data automatically.

 

You can use the following DAX measure. Remember to replace YourTable[Working_Hours] with the actual names of your table and column, and 'Calendar'[Date] with the date column from your dedicated Calendar table.

Rolling 3-Month Avg Working Hours =
VAR LastDate =
    MAX ( 'Calendar'[Date] )
VAR Period =
    DATESINPERIOD (
        'Calendar'[Date],
        LastDate,
        -3,
        MONTH
    )
VAR Result =
    CALCULATE (
        AVERAGE ( YourTable[Working_Hours] ),
        Period
    )
RETURN
    Result

This measure works by first capturing the last date in the current filter context (e.g., April 30th for the "April" row in your visual) using the LastDate variable. It then uses this date in the DATESINPERIOD function to generate a table of dates that spans the previous three months, including the current one. Finally, CALCULATE evaluates the AVERAGE of your Working_Hours column, but it replaces the visual's single-month filter with the new 3-month Period we just defined. This logic inherently handles the cumulative aspect at the beginning of your dataset; for the second month of data, it will average the first two months, and only from the third month onwards will it operate as a true rolling three-month calculation.

 

To implement this correctly, ensure you have a dedicated Calendar table marked as a date table in your model. There must be an active one-to-many relationship from this Calendar table's date column to the date column in your data table. Once that is set up, you can create a new measure in your table and paste this DAX code. After adjusting the names, you can add it to your visuals to see the correct rolling average.

 

Best regards,

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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.