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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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