Forum Discussion
Average Employee Tenure Over Time - Line Chart
Hi, all.
I'm working on a measure that I can't quite figure out, and I think it may be a relationship issue with my date table.
The goal: Produce a line chart with the average employee tenure on any specific date over the life of my data set.
What I have (2 Measures):
Hi Dave1mo1
Would something like this help?
Avg Tenure = VAR _Curr = SELECTEDVALUE( 'Date'[Date] ) VAR _Table = ADDCOLUMNS( FILTER( SUMMARIZE( ALL( 'Employee' ), 'Employee'[ID], 'Employee'[Date of Hire], 'Employee'[Actual Termination Date] ), [Date of Hire] <= _Curr && COALESCE( [Actual Termination Date], _Curr ) >= _Curr ), "__Days", DATEDIFF( [Date of Hire], _Curr, DAY ) + 1 ) VAR _Avg = AVERAGEX( _Table, [__Days] ) RETURN _AvgLet me know if you have any questions.
Average Employee Tenure Over Time - Line-Chart.pbix
5 Replies
- gmsambornSuper User
Hi Dave1mo1
Would something like this help?
Avg Tenure = VAR _Curr = SELECTEDVALUE( 'Date'[Date] ) VAR _Table = ADDCOLUMNS( FILTER( SUMMARIZE( ALL( 'Employee' ), 'Employee'[ID], 'Employee'[Date of Hire], 'Employee'[Actual Termination Date] ), [Date of Hire] <= _Curr && COALESCE( [Actual Termination Date], _Curr ) >= _Curr ), "__Days", DATEDIFF( [Date of Hire], _Curr, DAY ) + 1 ) VAR _Avg = AVERAGEX( _Table, [__Days] ) RETURN _AvgLet me know if you have any questions.
Average Employee Tenure Over Time - Line-Chart.pbix
- Dave1mo1Helper III
Sorry it took so long to get back to you - this is perfect, thank you!
Is there any way to tweak the measure so that it responds to filters on my filter panel, however? It's also possible I'm doing something wrong and it's not an issue with the measure, of course.
- gmsambornSuper User
Hi Dave1mo1
Can you provide the following?
1) Please provide sample data that covers your issue or question completely.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...2) Please show the expected outcome based on the sample data you provided.
https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523A .pbix file with sample data would be best.