I'm trying to imitate this report (page 3) where it slices active headcount and all the other metrics (1) by date and (2) by department.
My data looks like this (with relationships, of course):
ID | Name | DEPID | Hired Date | Terminated Date | Terminated (Y/N) |
---|---|---|---|---|---|
1 | John | 2 | 1/1/2019 | 2020/12/31 | Y |
2 | Jane | 2 | 1/3/2018 | 2019/07/26 | Y |
3 | Jack | 1 | 1/5/2022 | null | N |
Using the following measure, I was able to extract total number of employees by date, but I wasn't able to filter by department:
CountOfActive =
var _selectedDate = MAX('Calendar'[Date])
return
CALCULATE(COUNTROWS('Table'); filter(ALL('Table'); Table[HIREDDATE] <= VALUE(_selectedDate) && (Table[TERMINATEDDATE] >= VALUE(_selectedDate) || ISBLANK(Table[TERMINATEDDATE]))))
My ideal output is something like the following (where I'll create a table for each department and list the number of active employees, then join them to my department key table afterwards so I can slice them):
Date | Count of Active Employees | Department |
---|---|---|
2019/1/1 | 3 | Retail |
2019/1/2 | 3 | Retail |
2019/1/3 | 4 | Retail |
... | ... | ... |
The "Date" column would be a calendar table built with CALENDAR().
What should I do to achieve the last table based on the data I have?
My relationship schema looks like this.