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
TomLU123
Helper III
Helper III

Calculate the Average Headcount in a period

Dear Experts, 

 

I have a dataset like below. The database will refresh the active employee ID in following table once a day. The "Report Date" is the refresh date. 

 

For example, on 6/1/2018 and 6/2/2018, they are empty which means there are no employees.

On 6/3/2018, there are 4 employees joined.

On 6/4/2018, there are 4 employeess (no one join or left).

On 6/5/2018, there are 3 employees (one left).

 

I sitll wish to create a to create a measure to calculate the Average Headcount of the period by Sumimg the not empty headcount of the erlist date and not empty headcount of the latest date's the user choose, and then divided by 2.

 

For example, if the user choose 6/1/2018 to 6/5/2018, the Average Headcount of the period= (4+3)/2.

If the user choose 6/3/2018 to 6/4/2018, the Average Headcount of the period = (4+4)/2

 

Report DateEmployee ID
6/1/2018 
6/2/2018 
6/3/2018111
6/3/2018222
6/3/2018333
6/3/2018444
6/4/2018111
6/4/2018222
6/4/2018333
6/4/2018444
6/5/2018111
6/5/2018

222

6/5/2018

333

 

How should we write the expression to achieve that?

Many thanks!

 

Best regards,

Tom

1 ACCEPTED SOLUTION
SteveCampbell
Memorable Member
Memorable Member

You can try:

 

Average Headcount  = 
VAR _earliest_date = CALCULATE(MIN(Table[Report Date]),Table[Employee ID]<>BLANK())
VAR _latest_date = CALCULATE(MAX(Table[Report Date]),Table[Employee ID]<>BLANK())

RETURN

DIVIDE(
     COUNTROWS(FILTER(Table,Table[Report Date] = _earliest_date) )
   + COUNTROWS(FILTER(Table,Table[Report Date] = _latest_date) )
 ,
     2
)

and replace Table with the name of your table.



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

 

If the earliest date is 6/1/2018, then how will one compute the "non empty headcount of the earliest date"?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
SteveCampbell
Memorable Member
Memorable Member

You can try:

 

Average Headcount  = 
VAR _earliest_date = CALCULATE(MIN(Table[Report Date]),Table[Employee ID]<>BLANK())
VAR _latest_date = CALCULATE(MAX(Table[Report Date]),Table[Employee ID]<>BLANK())

RETURN

DIVIDE(
     COUNTROWS(FILTER(Table,Table[Report Date] = _earliest_date) )
   + COUNTROWS(FILTER(Table,Table[Report Date] = _latest_date) )
 ,
     2
)

and replace Table with the name of your table.



Did I answer your question? Mark my post as a solution! Proud to be a Super User!


Connect with me!
Stay up to date on  
Read my blogs on  



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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.