Forum Discussion
Calculation on headcount and leavers_moving average
- Anonymous3 years ago
Hi anony711 ,
First we need a calendar table like:
relationships:
Please try:
Measure = VAR _min_date = MIN('Calendar'[Date]) VAR _max_date = EDATE(_min_date,12) VAR _start_monthyear = MAX('Calendar'[MonthYear]) VAR _end_monthyear = CALCULATE(MAX('Calendar'[MonthYear]),FILTER(ALL('Calendar'),'Calendar'[Date]=_max_date-1)) VAR _leavers = CALCULATE(SUM('Table3'[Number of leavers]),FILTER(ALL('Calendar'),'Calendar'[Date]>=_min_date&&'Calendar'[Date]<_max_date)) VAR _number_of_employees_at_the_start = CALCULATE(MAX('Table1'[Starting headcount]),'Calendar'[Date] = _min_date) VAR _max_date_2 = CALCULATE(MAX('Table2'[Date]),FILTER(ALL('Table2'),'Table2'[Date]<_max_date)) VAR _number_of_employees_at_the_end = CALCULATE(MAX('Table2'[Ending headcount]),'Calendar'[Date] = _max_date_2) VAR _result = DIVIDE(_leavers,(_number_of_employees_at_the_start+_number_of_employees_at_the_end)/2) RETURN _resultBest Regards,
Gao
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
Hi anony711 ,
First we need a calendar table like:
relationships:
Please try:
Measure =
VAR _min_date = MIN('Calendar'[Date])
VAR _max_date = EDATE(_min_date,12)
VAR _start_monthyear = MAX('Calendar'[MonthYear])
VAR _end_monthyear = CALCULATE(MAX('Calendar'[MonthYear]),FILTER(ALL('Calendar'),'Calendar'[Date]=_max_date-1))
VAR _leavers = CALCULATE(SUM('Table3'[Number of leavers]),FILTER(ALL('Calendar'),'Calendar'[Date]>=_min_date&&'Calendar'[Date]<_max_date))
VAR _number_of_employees_at_the_start = CALCULATE(MAX('Table1'[Starting headcount]),'Calendar'[Date] = _min_date)
VAR _max_date_2 = CALCULATE(MAX('Table2'[Date]),FILTER(ALL('Table2'),'Table2'[Date]<_max_date))
VAR _number_of_employees_at_the_end = CALCULATE(MAX('Table2'[Ending headcount]),'Calendar'[Date] = _max_date_2)
VAR _result = DIVIDE(_leavers,(_number_of_employees_at_the_start+_number_of_employees_at_the_end)/2)
RETURN
_result
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data