Forum Discussion
Dynamic Headcount Calculation Ignoring Date Context but Respecting Slicers in Power BI
I am trying to calculate starting and ending headcount per month using a Date table.
My HC table contains employee joining dates (and optionally leaving dates). The challenge is to calculate cumulative headcount while ensuring slicers (like Department, Location) still work.
Currently, using ALL() breaks slicers.
HC Table
EmployeeID
DOJ (Date of Joining)
LWD (optional)
Date Table
Date
Month
Year
Relationship
DateTable[Date] → HC[DOJ] (Active)
What I Want / Expected Result -
For each month:
Starting HC = Employees active at beginning of month
Ending HC = Employees active at end of month
Should respond to slicers like Department, Location
Please try the measures below:
Ending HC = VAR _EndOfMonth = EOMONTH ( MAX ( 'Date'[Date] ), 0 ) RETURN CALCULATE ( COUNTROWS ( HC ), REMOVEFILTERS ( 'Date' ), HC[DOJ] <= _EndOfMonth, OR ( ISBLANK ( HC[LWD] ), HC[LWD] > _EndOfMonth ) )Starting HC = VAR _StartOfMonth = DATE ( YEAR ( MIN ( 'Date'[Date] ) ), MONTH ( MIN ( 'Date'[Date] ) ), 1 ) RETURN CALCULATE ( COUNTROWS ( HC ), REMOVEFILTERS ( 'Date' ), HC[DOJ] < _StartOfMonth, OR ( ISBLANK ( HC[LWD] ), HC[LWD] >= _StartOfMonth ) )
5 Replies
- cengizhanarslan
Super User
Please try the measures below:
Ending HC = VAR _EndOfMonth = EOMONTH ( MAX ( 'Date'[Date] ), 0 ) RETURN CALCULATE ( COUNTROWS ( HC ), REMOVEFILTERS ( 'Date' ), HC[DOJ] <= _EndOfMonth, OR ( ISBLANK ( HC[LWD] ), HC[LWD] > _EndOfMonth ) )Starting HC = VAR _StartOfMonth = DATE ( YEAR ( MIN ( 'Date'[Date] ) ), MONTH ( MIN ( 'Date'[Date] ) ), 1 ) RETURN CALCULATE ( COUNTROWS ( HC ), REMOVEFILTERS ( 'Date' ), HC[DOJ] < _StartOfMonth, OR ( ISBLANK ( HC[LWD] ), HC[LWD] >= _StartOfMonth ) ) - ryan_mayu
Super User
pls provide some sample data and expected output
- krishnakanth240
Super User
Hi nareshbs18
Can you share the sample data in text format to give a try and sample output view you are looking for.
- v-moharafi-msft
Community Support
Hi nareshbs18 ,
Thank you for reaching out to Microsoft Fabric Community and Thanks to cengizhanarslan for Sharing valuable insights.Just wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions.
Best Regards,Abdul Rafi.
- v-moharafi-msft
Community Support
Hi nareshbs18 ,
Could you please confirm if the issue has been resolved? If not, feel free to reach out if you have any further questions.
Your update would be helpful for other members who may face a similar issue.
Best Regards,
Abdul Rafi