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
ggargan
Frequent Visitor

Problems calculating 12 month rolling average

Hello. Havent done this before.

 

Trying to calculate the 12 month rolling average for a rate (Measure). It doesn't seem to be working and is just returning the same value as the current month's value (not the average of the last 12 months).

 

ggargan_1-1663943490403.png

This is the DAX in the calculation 

ggargan_2-1663943517012.png

 

Would be very greatful if someone could point out where im going wrong! Let me know if you need any more info.

 

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

Hi @ggargan ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1664172883737.png

2. create a measure with below dax formula

Measure =
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Date] )
VAR tmp =
    CALCULATETABLE (
        VALUES ( 'Table'[Sales] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Date] IN DATESINPERIOD ( 'Table'[Date], cur_date, -12, MONTH )
        )
    )
RETURN
    AVERAGEX ( tmp, [Sales] )

3. add a table visual with measure and column

vbinbinyumsft_1-1664173003946.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
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-binbinyu-msft
Community Support
Community Support

Hi @ggargan ,

Please try below steps:

1. below is my test table

Table:

vbinbinyumsft_0-1664172883737.png

2. create a measure with below dax formula

Measure =
VAR cur_date =
    SELECTEDVALUE ( 'Table'[Date] )
VAR tmp =
    CALCULATETABLE (
        VALUES ( 'Table'[Sales] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Date] IN DATESINPERIOD ( 'Table'[Date], cur_date, -12, MONTH )
        )
    )
RETURN
    AVERAGEX ( tmp, [Sales] )

3. add a table visual with measure and column

vbinbinyumsft_1-1664173003946.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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 by the Month number.  Create a relationship (Many to One and Single) from the Date column of the Data Table to the Date column of the Calendar Table.  To your Table visual, drag Year and Month name from the Calendar Table.  Assuming 5. TRIR is a measure that you hav already written ,write this measure:

 12 months rolling average = calculate([5. TRIR],datesbetween(Calendar[Date],edate(min(calendar[date)),-11),max(calendar[date])))

Hope this helps.


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

Hi, @ggargan 

 

Did you try quick measure for that, it might work?




Did I answer your question? Mark my post as a solution!


https://allure-analytics.com/
https://www.youtube.com/channel/UCndD_QZVNB_JWYLEmP6KrpA
https://www.linkedin.com/company/77757292/

Proud to be a Super User!




lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

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.