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
ppdas2112
Helper I
Helper I

3 (or n) months Rolling Average ignoring blanks and for future months

Hello experts, 

Urgent request! Kindly help me! I have the following table.

  • I require 3 (or any n) months Rolling Average, but ignoring the blank Spend rows while counting the number of months in denominator.
  • For example, for 3 months rolling average in Mar-19, the calculation would be (248+176)/2 and not (248+176)/3.
  • Also require the Rolling Average values for future months (till they become zero, which they eventually will)

ppdas2112_0-1653940591830.png

Thanks in advance!

@amitchandak @johnt75 @tamerj1 @Jihwan_Kim @PaulDBrown @truptis @Ashish_Mathur @AlexisOlson @parry2k @Greg_Deckler @BA_Pete @mahoneypat @Vera_33 @Vijay_A_Verma @edhans @jennratten @smpa01 @Thingsclump  @SpartaBI @MFelix @speedramps @DataInsights @Shishir22 

1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @ppdas2112 ,

Please refer to my pbix file to see if it helps you.

Create a measure.

 

Measure =
VAR before_three =
    EDATE ( MAX ( 'Table'[date] ), -2 )
VAR _sumvalue =
    CALCULATE (
        SUM ( 'Table'[Spend] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] >= before_three
                && 'Table'[date] <= MAX ( 'Table'[date] )
        )
    )
VAR _countrow =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] >= before_three
                && 'Table'[date] <= MAX ( 'Table'[date] )
        )
    )
RETURN
    _sumvalue / _countrow

 

vpollymsft_0-1654133726390.png

If I have misunderstood your meaning, please provide more details with you desired output.(Preferably in picture form)

 

Best Regards

Community Support Team _ Polly

 

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

4 REPLIES 4
v-rongtiep-msft
Community Support
Community Support

Hi @ppdas2112 ,

Please refer to my pbix file to see if it helps you.

Create a measure.

 

Measure =
VAR before_three =
    EDATE ( MAX ( 'Table'[date] ), -2 )
VAR _sumvalue =
    CALCULATE (
        SUM ( 'Table'[Spend] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] >= before_three
                && 'Table'[date] <= MAX ( 'Table'[date] )
        )
    )
VAR _countrow =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] >= before_three
                && 'Table'[date] <= MAX ( 'Table'[date] )
        )
    )
RETURN
    _sumvalue / _countrow

 

vpollymsft_0-1654133726390.png

If I have misunderstood your meaning, please provide more details with you desired output.(Preferably in picture form)

 

Best Regards

Community Support Team _ Polly

 

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

ppdas2112
Helper I
Helper I

Hi Ashish, that formula will take into consideration months without Spend value too

have you tried my suggested measure.  If it does not give the correct result, then share the download link of your PBI file and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with calculated column formulas for Year, Month name and Month number.  Sort the Month name column by Month number.  Create a relationship (Many to One and Single) from the Date column of your Data Table to the Date column of the Calendar Table.  To your visual, drag Year and Month name from the Calendar Table.  Write these measures:

Total spend = sum(Data[Spend])

Rolling 3 month spend = averagex(summarize(filter(calendar,datesbetween(calendar,edate(min(calendar[date]),-2),max(calendar[date]))),Calendar[Year],Calendar[Month name],"ABCD",[total spend]),[abcd])

If this does not work, then share the link of your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.