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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
dpearson_soco
Regular Visitor

Running Total then Avg over a specified time period

I have a situation for accounting where they want to look at the Running totals for our AR and then compare what the Average was for the last 13 months for trending. I can get to the running totals just fine, but cannot figure out how to then average those running totals for the last 13 months:

Here is what I have so far:

DSO_AvgAR =
VAR LastCurrentDate = MAX ( 'd_Date'[CalendarDate] )
VAR Period13 = DATESINPERIOD ( 'd_Date'[CalendarDate], LastCurrentDate, - 13, MONTH )
VAR RunningAR = CALCULATE(SUMX(f_GeneralLedger,f_GeneralLedger[Amount]),d_Date[CalendarDate] <= LastCurrentDate, f_GeneralLedger[AccountNumber] in {"10225","10226","10250","10275","10300","10325","10350","10380","10381","10382","10383","10384","10385"})
Var AVG_AR = CALCULATE(AVERAGEX(VALUES ('d_Date'[YearMonth]), RunningAR), Period13)

RETURN AVG_AR

Here is some sample data of what the RunningAR looks like for the last 13 months:
MonthAR Value
1$339,022
2$487,064
3$386,998
4$388,119
5$432,743
6$434,630
7$413,986
8$483,239
9$439,252
10$563,513
11$696,451
12$454,170
13$388,795

The Average should be $454,460.18
1 ACCEPTED SOLUTION
johnt75
Super User
Super User

The problem is the RunningAR variable. Variables are only calculated once, so it is not being recalculated within the AVERAGEX, each month will use the same value. Either move the code for RunningAR inside the AVERAGEX or use that code to define a measure, and call the measure from within the AVERAGEX.

View solution in original post

1 REPLY 1
johnt75
Super User
Super User

The problem is the RunningAR variable. Variables are only calculated once, so it is not being recalculated within the AVERAGEX, each month will use the same value. Either move the code for RunningAR inside the AVERAGEX or use that code to define a measure, and call the measure from within the AVERAGEX.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.