Forum Discussion
Anonymous
6 years agoNot applicable
Employee Turnover % by Month
Hey guys, I've been struggling to find specific DAX answers to this above question, although it appears its been asked multiple times. I'm attemping to provide the Employee Turnover % by Month - th...
- Anonymous6 years ago
// Truth is you don't have to limit the calculation // to just a month. You can calculate what you want // on ANY period of time. This will, of course, // also work for months in particular. // Please do NOT connect your Dates table to any // of the fields in the Employees table. [# Emps At Start Of Period] = // These are emps that have // hire date <= start of period var __periodStart = MIN( Dates[Date] ) return CALCULATE( countrows( Employees ), KEEPFILTERS( Employees[Hire Date] <= __periodStart ) ) [# Emps At End Of Period] = // These are emps that have // their hire date <= end of period // and their termination date >= // end of period. var __periodEnd = MAX( Dates[Date] ) return CALCULATE( countrows( Employees ), KEEPFILTERS( Employees[Hire date] <= __periodEnd ), KEEPFILTERS( Employees[Termination Date] >= __periodEnd || isblank( Employees[Termination Date] ) ) ) [# Emps Terminated During Period] = // self-explanatory var __periodStart = MIN( Dates[Date] ) var __periodEnd = MAX( Dates[Date] ) return CALCULATE( countrows( Employees ), KEEPFILTERS( __periodStart <= Employees[Termination Date] ), KEEPFILTERS( Employees[Termination Date] <= __periodEnd ) )
Anonymous
6 years agoNot applicable
// Truth is you don't have to limit the calculation
// to just a month. You can calculate what you want
// on ANY period of time. This will, of course,
// also work for months in particular.
// Please do NOT connect your Dates table to any
// of the fields in the Employees table.
[# Emps At Start Of Period] =
// These are emps that have
// hire date <= start of period
var __periodStart = MIN( Dates[Date] )
return
CALCULATE(
countrows( Employees ),
KEEPFILTERS( Employees[Hire Date] <= __periodStart )
)
[# Emps At End Of Period] =
// These are emps that have
// their hire date <= end of period
// and their termination date >=
// end of period.
var __periodEnd = MAX( Dates[Date] )
return
CALCULATE(
countrows( Employees ),
KEEPFILTERS( Employees[Hire date] <= __periodEnd ),
KEEPFILTERS(
Employees[Termination Date] >= __periodEnd
||
isblank( Employees[Termination Date] )
)
)
[# Emps Terminated During Period] =
// self-explanatory
var __periodStart = MIN( Dates[Date] )
var __periodEnd = MAX( Dates[Date] )
return
CALCULATE(
countrows( Employees ),
KEEPFILTERS( __periodStart <= Employees[Termination Date] ),
KEEPFILTERS( Employees[Termination Date] <= __periodEnd )
)
- Anonymous6 years agoNot applicable
Anonymous
Right away when I'm trying to implement the first DAX for "# Emps At start of period" I'm getting an error that "Too many arguments were passed to the COUNTROWS function, maximum is 1." Is there some other kind of manipulation I need to do to the hire date field in my data?
- Anonymous6 years agoNot applicableThis is because I've got too many things to think of and I don't create models to check my code. I just write it. Try the code above now.
- Anonymous6 years agoNot applicable
Thanks for the quick response, I'll try in the next few minutes and then give you an update.