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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.