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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Winter_king94
Helper I
Helper I

Accumulating Average over past 12 months

Hi all, 

I'm stumped. I am trying to create a view where based on the current month, a line chart will calculate the accumulating average for the previous 12 months. 

For example, the current month is June 2025, so I want to see the accumulating average for Jun 2024- May 2025. I don't want to have to change a slicer to get this to update, I want the measure to update itself each month.

For the accumulating average, I want to have the measure sum together the count of Days to Close and then divide that by how many months were accumulated. For example- (Jun'24 +Jul'24)/ 2. 

Below is an image in excel of what I'm trying to get at: 

Winter_king94_0-1749652134403.png

 

 

In Power BI, I've only been able to get the rolling 12 months average (but it shows all the months and does not limit to only 12 months)

Avg Days to Close Moving12MO =

    VAR NumOfMonths = 12
    VAR _Maxdate = MAX('Date'[Date]) /*6/5/25*/
    VAR LastCurrentDate = EOMONTH(_Maxdate, -1) /*5/31/2025*/
    VAR _StartDate = EOMONTH(_maxdate, -12) +1 /*6/1/2024*/
    VAR Period =  DATESINPERIOD ( 'Date'[Date], LastCurrentDate, - NumOfMonths, MONTH )
 
    VAR Result =
        CALCULATE(
            AVERAGEX(      
                    VALUES('Date'[Month And Year]) /*allows you to get the average for each month*/    
                    , 'Opportunity'[Days2Close Test]        
                    ),      
                DATESBETWEEN('Date'[Date], _StartDate, _Maxdate)        
                )      

    RETURN
    Result

Winter_king94_1-1749578828844.png

 

'Date' is marked as a date table. 

1 ACCEPTED SOLUTION

Hi,

Download the PBI file from here.

Hope this helps.

Ashish_Excel_0-1749832003334.png

 

View solution in original post

9 REPLIES 9
v-echaithra
Community Support
Community Support

Hi @Winter_king94 ,

Thank you for reaching out to Microsoft Community.
Try with this DAX 

Accumulating_avg =
VAR Today = TODAY()
VAR Lastfullmonth = EOMONTH(Today, -1)
VAR StartDate = EOMONTH(Lastfullmonth, -11) + 1


VAR MonthsInScope =FILTER (ADDCOLUMNS (SUMMARIZE ( 'Date', 'Date'[YearMonth] ),
"@MonthEnd", EOMONTH (MIN ('Date'[Date] ), 0)),[@MonthEnd] >= StartDate && [@MonthEnd] <= LastFullMonth)


VAR Result =AVERAGEX (MonthsInScope,
VAR Currentmonthend = [@MonthEnd]
VAR Currentmonthstart = EOMONTH(Currentmonthend, 0) - DAY(Currentmonthend) + 1

VAR Datatillthismonth =CALCULATETABLE ('Opportunity',
'Date'[Date] >= StartDate && 'Date'[Date] <= Currentmonthend)

VAR Totaldays = CALCULATE (SUM ( 'Opportunity'[Days2Close Test] ),Datatillthismonth)

VAR MonthsSoFar =CALCULATE (DISTINCTCOUNT ( 'Date'[YearMonth] ),
'Date'[Date] >= StartDate && 'Date'[Date] <= Currentmonthend)
RETURN DIVIDE ( TotalDays, Monthssofar ))
RETURN Result


additionally format your month for the chart like Month = FORMAT('Date'[Date], "yyyy MMM").

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

 

Regards,

Chaithra.







This unfortunately isn't working for me. The measure is coming back blank.
I took your DAX and tried to tweak it but to no avail. What am I doing wrong? 
*Also wanted to mention that there is an inactive relationship between the Opportunity table and the Date table. The relationship is 'Opportunity'[CloseDate_CDT] to the 'Date'[Date] field. 

Avg Days to Close Moving12MO_3 =

    VAR _Maxdate = MAX('Date'[Date]) /*6/5/25*/
    VAR LastFullMonth = EOMONTH(_Maxdate, -1) /*5/31/2025- returns last day of the previous month*/
    VAR _StartDate = EOMONTH(_maxdate, -12) +1 /*6/1/2024*/
    VAR _Days2Close =CALCULATE (SUM('Opportunity'[Days to Close]), USERELATIONSHIP('Date'[Date], 'Opportunity'[CloseDate_CDT]))


    VAR MonthsInScope =FILTER (
            ADDCOLUMNS (
                SUMMARIZE (
                     'Date', /*table to summarize*/
                     'Date'[Month & Year] ) /*columns to group by*/
                ,"@MonthEnd",  /*NEW COLUMN name*/
                EOMONTH (MIN ('Date'[Date] ), 0)), /*expression to create new column*/
            [@MonthEnd] >= _StartDate && [@MonthEnd] <= LastFullMonth)

    VAR Result =AVERAGEX (MonthsInScope,
        VAR Currentmonthend = [@MonthEnd]
        VAR Currentmonthstart = EOMONTH(Currentmonthend, 0) - DAY(Currentmonthend) + 1 /*give the last day of the month, then subrtact the number of days and add 1*/

        VAR Datatillthismonth =CALCULATETABLE ('Opportunity','Opportunity'[CloseDate_CDT] >= _StartDate && 'Opportunity'[CloseDate_CDT] <= Currentmonthend) /*getting all opportunities with a close date between the date parameters*/

        VAR Totaldays = CALCULATE (_Days2Close, Datatillthismonth)

        VAR MonthsSoFar =CALCULATE (DISTINCTCOUNT ( 'Date'[Month & Year] ),'Date'[Date] >= _StartDate && 'Date'[Date] <= Currentmonthend)
       
        RETURN DIVIDE ( TotalDays, Monthssofar ))
   
    RETURN
     Result
Ashish_Excel
Resolver V
Resolver V

Hi,

Share some data to work with and show the expected result.  Share data in a format that can be pasted in an MS Excel file.

The screenshot of the excel with the chart is the data & expected result. Is there more you need outside of that? The year/month and sum of days to close is the raw data. The 'Accumulating Average' column is the desired result.

Share data in a format that can be pasted in an MS Excel file.  Is the FY June to May i.e. is that the order in which you want to see the months?  Isn't there a proper date column in your dataset?

The table below is a snippet of raw data from the Opportunity table from 2024- 2025. It has the number of days it took each opportunity to close and the date it closed. The Opportunity table has an inactive relationship with the Date table. 'Opportunity'[ClosedDate_CDT] --> 'Date'[Date].

If I am looking at the report on 6/12/2025 (which is not a finished month), I want to see the previous 12 months and their accumulating average. The first month that should show in the visual is 6/2024 and the last month is 5/2025. If I look at this report in August 2025, I want to see the data for 8/2024-7/2025. Hopefully that's what you were looking for.


opportunityidCloseDate_CDTDays to Close
D94CF3E9-73B9-411F-85FC-AC24F06400CF10/24/2024647
827DCF94-2648-4DC4-AA1D-39BC3C60BA2B11/13/202479
24BA3194-72A4-4A4D-8FC7-CDBA57D7D0F712/6/2024212
627BAEBD-D48A-4CF2-8F66-136C2229BA778/8/2024766
168895D9-B8CD-4B55-9A31-C14ED33BC0B63/19/2024404
EE7267CB-77AB-486F-910B-116D922973113/31/2024971
A40DCA2C-CE71-46CC-86D8-94408BD1B73812/4/20241133
0B2562E1-0113-498D-96CB-F9E1B8CBEC345/14/2024426
3767D7E5-D670-4C82-95E4-3F1E10BD919A9/11/2024121
9CED3EA9-210F-4645-A443-284A8C4AD05D8/8/2024150
BD3CBF08-9A1A-4FFA-A2CB-A591278091529/16/2024589
FC646680-6165-4705-85F8-A7986A17494E9/16/2024432
7F03B000-8D55-4F50-9E03-680F10AC87845/15/2024950
3CB9B83C-83E8-EF11-A731-000D3A37A3924/24/202573
657BDFD2-F404-F011-BAE3-000D3A36199C5/15/202558
B534341A-51E6-49A3-BFEC-1E10478F701C10/13/2024544
AFE3039E-2CED-4FB3-9E72-1EFA97154F0C5/5/2024520
69704B54-7A0F-4547-8A35-42D6648C194D3/4/2024252
C407BADE-E1AD-4DE4-9A7A-A6B3747136EE12/11/202443
A862AF7C-9446-47B0-BE78-2C1BCE01419712/11/202443
934BBD19-A53C-4091-93AD-77F2CA364AFD11/5/20247
CA30D797-D11D-4222-B6E2-5B5D9140AE486/19/2024709
64111240-8866-4C94-A532-A9841CF4638B6/8/2025222
76EA7EF4-7C3F-4000-A64A-A6FA400C515510/28/20244
424C8560-23C5-4592-87BD-3E109C95D94C10/24/2024560
003F8125-D721-F011-998A-000D3A36199C5/4/202510
9ED94E23-50F3-45B8-8727-09F13BE0087C2/1/2024764
A04F4B6E-0208-47C6-A1CA-F7140E1466625/16/20249
DE922F18-FA67-41E0-8E49-E3DA8331D94A8/8/2024127
F1EBB8A5-7623-F011-8C4D-6045BD0252386/10/202545
4F29EF79-2495-4114-889D-64A9E40A2DAF1/8/2025320
15CDB247-5EC4-4902-B450-AA40ED21836512/3/2024343
5E2BAB98-778B-4549-86C0-C5311DAA9B5212/5/2024175
DD8C91E7-0E67-4D8E-AC92-97DB2925D3738/12/2024810
5F953C1F-2CDD-42A2-BDD2-A69E3D060F599/11/20248
BA2DD2F3-84DF-4FAF-BC43-5FE37DAA21972/18/2025282
A0368570-D9E0-4DC2-84F3-4B33730206B32/19/2025187
3DDE9D3F-63CF-4ABB-9096-8709FCE8F20C7/12/20241114
21D4D912-E12E-4566-A5F2-E524F5176E056/2/2024269
3B741CB0-C410-4262-BD04-62E9076CE5487/7/20241354
5B89722B-B50D-47C8-AC40-300678BD8A5710/24/2024176
95966042-A24D-4CAA-BD53-CAC6C42624CE12/3/202454
AE56920F-5886-EF11-AC21-6045BD01A9FD3/27/2025170
453A86E6-2DAC-41E9-95D0-B33F727A17485/16/2024798
D87E48B5-EBCC-ED11-B597-00224809C6771/18/2024298
AF885A3E-A613-44DF-8BB2-F8551012C2666/11/2024884
513776B2-EBCC-ED11-B597-00224809CBC26/5/2024437
085F8AA3-8BC9-45CF-8729-0581CC1F8BB711/13/2024234
62CCDA46-C380-EA11-811B-0050569122EF11/26/20241685
E7D766EC-3C1F-46AB-B5C6-31CAB3FEFEE46/17/2024380
D3C291B7-EBCC-ED11-B597-00224809C2437/8/2024470

 

Hi,

Download the PBI file from here.

Hope this helps.

Ashish_Excel_0-1749832003334.png

 

Thank you! Really appreciate all your help!

You are welcome.

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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