Reply
sreddy47652
Helper III
Helper III
Partially syndicated - Outbound

rolling average for 3 months showing same value

Hi team,

i am trying to create the rolling average for 3 months but it was giving same values as base value, can you help me to fix for rolling average for 3 months.

sreddy47652_0-1732102206763.png

 

4 ACCEPTED SOLUTIONS
johnt75
Super User
Super User

Syndicated - Outbound

You can try

Rolling Average =
VAR DatesToUse =
    WINDOW (
        -2,
        REL,
        0,
        REL,
        ALLSELECTED ( 'Date'[Year], 'Date'[Month number] ),
        ORDERBY ( 'Date'[Year], ASC, 'Date'[Month number], ASC )
    )
VAR Result =
    AVERAGEX ( DatesToUse, CALCULATE ( DISTINCTCOUNT ( 'Table'[User ID] ) ) )
RETURN
    Result

View solution in original post

divyed
Super User
Super User

Syndicated - Outbound

Hello @sreddy47652 ,

 

You can use below dax for your purpose , please replace table names and fileds:

 

rolling_3_month_Avg =
AVERAGEX(
    WINDOW(
        -2,REL,0,REL,
        ALLSELECTED(Test_Avg[Month_number],Test_Avg[Year],Test_Avg[Users]),
        ORDERBY(Test_Avg[Month_number]),
        PARTITIONBY(Test_Avg[Year])
    ),
    CALCULATE(AVERAGE(Test_Avg[Users])
)
)
 
divyed_0-1732109116311.png

 

Did I answer your query ? Mark this as solution if this helps, appreciate your Kudos.

 

Cheers

 

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

View solution in original post

Syndicated - Outbound

Hello @sreddy47652 ,

 

It is giving as expected , here is the illustration, please suggest if you have different logic

 

divyed_0-1732174533109.png

 

Cheers

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

View solution in original post

v-denglli-msft
Community Support
Community Support

Syndicated - Outbound

Hi @sreddy47652 ,

Please try the following dax.

Rolling Average (3 Months) = 
VAR difference = DATEDIFF(MINX(ALL('Table'),'Table'[Date]),MAX('Table'[Date]),MONTH) --The difference in months from the min date.
VAR _value = CALCULATE(DISTINCTCOUNT('Table'[Users]) ,DATESINPERIOD('Table'[Date],MAX('Table'[Date]),-3,MONTH)) --Total value of 3 months.
RETURN
SWITCH(
    TRUE(),
    difference=0,_value,
    difference=1,_value/2,
    difference>1,_value/3
  )

vdengllimsft_0-1732501696661.png

 

Please see the attached pbix for reference.

Best Regards,
Dengliang Li

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

14 REPLIES 14
v-denglli-msft
Community Support
Community Support

Syndicated - Outbound

Hi @sreddy47652 ,

Please try the following dax.

Rolling Average (3 Months) = 
VAR difference = DATEDIFF(MINX(ALL('Table'),'Table'[Date]),MAX('Table'[Date]),MONTH) --The difference in months from the min date.
VAR _value = CALCULATE(DISTINCTCOUNT('Table'[Users]) ,DATESINPERIOD('Table'[Date],MAX('Table'[Date]),-3,MONTH)) --Total value of 3 months.
RETURN
SWITCH(
    TRUE(),
    difference=0,_value,
    difference=1,_value/2,
    difference>1,_value/3
  )

vdengllimsft_0-1732501696661.png

 

Please see the attached pbix for reference.

Best Regards,
Dengliang Li

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

divyed
Super User
Super User

Syndicated - Outbound

Hello @sreddy47652 ,

 

You can use below dax for your purpose , please replace table names and fileds:

 

rolling_3_month_Avg =
AVERAGEX(
    WINDOW(
        -2,REL,0,REL,
        ALLSELECTED(Test_Avg[Month_number],Test_Avg[Year],Test_Avg[Users]),
        ORDERBY(Test_Avg[Month_number]),
        PARTITIONBY(Test_Avg[Year])
    ),
    CALCULATE(AVERAGE(Test_Avg[Users])
)
)
 
divyed_0-1732109116311.png

 

Did I answer your query ? Mark this as solution if this helps, appreciate your Kudos.

 

Cheers

 

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/

Syndicated - Outbound

@divyed it's working some what better than earlier formulas but need rolling average like this below image, can you help me to fix this.

sreddy47652_0-1732110868920.png

 

Syndicated - Outbound

Hello @sreddy47652 ,

 

It is giving as expected , here is the illustration, please suggest if you have different logic

 

divyed_0-1732174533109.png

 

Cheers

LinkedIn : https://www.linkedin.com/in/neeraj-kumar-62246b26/
DataNinja777
Super User
Super User

Syndicated - Outbound

Hi @sreddy47652 ,

 

Here is a measure for calculating a 3-month rolling average at the month level:

Rolling Average (3 Months) = 
VAR CurrentMonth = MAX('Calendar'[Date])
RETURN 
    AVERAGEX(
        DATESINPERIOD('Calendar'[Date], CurrentMonth, -3, MONTH),
        CALCULATE(SUM('FactTable'[Value]))
    )

 

 

 

This measure calculates the rolling average by using the DATESINPERIOD function to define a 3-month window and then applies AVERAGEX to compute the average for the specified period. The calendar table ensures the calculation respects the relationship with the fact table.

 

Best regards,

johnt75
Super User
Super User

Syndicated - Outbound

You can try

Rolling Average =
VAR DatesToUse =
    WINDOW (
        -2,
        REL,
        0,
        REL,
        ALLSELECTED ( 'Date'[Year], 'Date'[Month number] ),
        ORDERBY ( 'Date'[Year], ASC, 'Date'[Month number], ASC )
    )
VAR Result =
    AVERAGEX ( DatesToUse, CALCULATE ( DISTINCTCOUNT ( 'Table'[User ID] ) ) )
RETURN
    Result

Syndicated - Outbound

i tried above forumala but it always return as 1 only instead of rolling average

Syndicated - Outbound

It works for me, see attached PBIX. I think there must be an issue in the calculation you're using where I put the DISTINCTCOUNT.

Syndicated - Outbound

@johnt75  it seems better than earlier formula but its not giving accurate results, i need rolling average below like this but based on month number. can you help me how to fix it.

sreddy47652_0-1732110729099.png

 

Syndicated - Outbound

Its is showing the rolling 3 month average, including the month itself. So in March it is showing the average over Jan, Feb and March. 

What formula are you using to calculate the average, and what about the numbers do you think is wrong ?

Syndicated - Outbound

No ,Formula is correct but when you rolling over next month it's showing average for 4 months viceversa but ideally it should show as below image

sreddy47652_0-1732120168224.png

 

Syndicated - Outbound

I don't understand what you mean that its showing the average for 4 months viceversa? The window function is producing 3 months and then you take the average of that.

From the PBIX I posted earlier

johnt75_0-1732120619564.png

 

shafiz_p
Super User
Super User

Syndicated - Outbound

Hi @sreddy47652 
It is better to provide representative date to get the exact solution.


However, you could try this:

RollingAvg3Months = 
CALCULATE(
    AVERAGEX(
        DATESINPERIOD(
            'DateTable'[Date],
            LASTDATE('DateTable'[Date]),
            -3,
            MONTH
        ),
        AVERAGE('YourTable'[Value])
    )
)

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution and a kudos!!

 

Best Regards,
Shahariar Hafiz

Syndicated - Outbound

i tried already above formula still returns same values for base value

avatar user

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)