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
datagorillagirl
Microsoft Employee
Microsoft Employee

Calculating Average Value using Beginning and Ending Value

I have the following three piece measures

CurrentHC = CALCULATE(SUM(HeadCountActuals[ActualPeopleCount]))
PreviousHC = CALCULATE (
    SUM( HeadCountActuals[ActualPeopleCount] ),
    'HeadCountActuals'[ActualPeopleCount] <> BLANK (),
    PARALLELPERIOD ( '2. Time'[Date], -1, MONTH )
)
monthcount = DISTINCTCOUNTNOBLANK(HeadCountActuals[FiscalMonthId])
AverageHC = DIVIDE([CHC]+[PHC],[monthcount]*2)

My first question is help simplifying the model to include CurrentHC, PreviousHC and monthcount as variables

My second question is when I select consecutive months such as in
datagorillagirl_0-1664331943333.pngdatagorillagirl_1-1664332003791.png

However when there is a gap in dates, the AverageHC returns incorrect value

datagorillagirl_2-1664332147272.png

For example in above the AverageHC displays 17.5 when it should be 14.25

The basis of the calculation is below

datagorillagirl_6-1664332259043.png

 

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

 

Average HC = 
var a = ADDCOLUMNS(VALUES(Headcount[Month]),"CHC",var m=[Month] return CALCULATE(sum(Headcount[HC]),Headcount[Month]=m))
var b = ADDCOLUMNS(a,"PHC",var m=[Month] return if([Month]=0,[CHC],CALCULATE(sum(Headcount[HC]),Headcount[Month]=m-1)))
return averagex(b,DIVIDE([CHC]+[PHC],2,0))

 

 

lbendlin_0-1664408769431.png

 

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

 

Average HC = 
var a = ADDCOLUMNS(VALUES(Headcount[Month]),"CHC",var m=[Month] return CALCULATE(sum(Headcount[HC]),Headcount[Month]=m))
var b = ADDCOLUMNS(a,"PHC",var m=[Month] return if([Month]=0,[CHC],CALCULATE(sum(Headcount[HC]),Headcount[Month]=m-1)))
return averagex(b,DIVIDE([CHC]+[PHC],2,0))

 

 

lbendlin_0-1664408769431.png

 

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.