Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Employee Average Tenure not working

Hi All,   I am trying to calculate the Average Tenure for employees over time AND trying to see if its possible to pivot this information by location, departments, status etc.    I am struggling ...
  • Anonymous's avatar
    Anonymous
    4 years ago

    I working on it but i'm too slow i have to stop it.
    Try this, where the StartDate table is your DataTable (i have set a reletionship one way and not both like you).
    Here there are the day in for every employ. 
    You have to stop the count when they go out.
    If you need i'll give the pbix.
    I hope i help you.

    AverageTenurev2 = 
    
    VAR _currentMonth = SELECTEDVALUE(StartDate[Month])
    VAR HireDate = CALCULATE(MAX(FactTable[Start Date]), ALLEXCEPT(FactTable, FactTable[ID]))
    VAR TermDate = CALCULATE(MAX(FactTable[End Date]), ALLEXCEPT(FactTable, FactTable[ID]))
    VAR _EOM = EOMONTH(TODAY(),-1)
    RETURN
    
    VAR _StartDate = IF(HireDate <= _currentMonth, HireDate, blank())
    VAR _EndDate = IF(TermDate=BLANK(), _EOM, IF(EOMONTH(TermDate,0)<= _currentMonth, MIN(_currentMonth, TermDate), blank()))
    
    VAR day_in = IF(_StartDate < _currentMonth, DATEDIFF(_StartDate, _currentMonth, day), BLANK())
    
    RETURN day_in