Forum Discussion
Calculate Employee Age Correctly
- 5 years ago
I think your measure gives you calender years. Try this:
Employee Age = VAR SelectedDate =MAX(Dates[Date]) VAR CurrentEmployee = MAX('Table'[BirthDate]) VAR YearDiff = YEAR(SelectedDate) - YEAR(CurrentEmployee) RETURN IF ( MONTH(SelectedDate) > MONTH(CurrentEmployee), YearDiff, IF (MONTH(SelectedDate) = MONTH(CurrentEmployee) && DAY(SelectedDate) >= DAY(CurrentEmployee), YearDiff, YearDiff-1 ) ) - 5 years ago
Yeah, that's true. Maybe this:
Result = VAR EmployeeAge = SUM('Table'[Value]) VAR Result = IF( OR( TODAY() >= MAX('Table'[StartDate]) && TODAY() <= MAX('Table'[EndDate]), TODAY() >= MAX('Table'[StartDate]) && ISBLANK(MAX('Table'[EndDate]))), EmployeeAge, BLANK() ) RETURN Result
I think your measure gives you calender years. Try this:
Employee Age =
VAR SelectedDate =MAX(Dates[Date])
VAR CurrentEmployee = MAX('Table'[BirthDate])
VAR YearDiff = YEAR(SelectedDate) - YEAR(CurrentEmployee)
RETURN
IF ( MONTH(SelectedDate) > MONTH(CurrentEmployee),
YearDiff,
IF (MONTH(SelectedDate) = MONTH(CurrentEmployee) && DAY(SelectedDate) >= DAY(CurrentEmployee),
YearDiff,
YearDiff-1
)
)- yaman1235 years ago
Post Partisan
Thank you! This works a treat!
- yaman1235 years ago
Post Partisan
Hi Johanno,
Is there a way to use the dax measure you sent and only show employees who were active on the chosen month year also? would a seperate measure be required?
- Johanno5 years ago
Continued Contributor
You could solve it in the same measure. If you want to remove inactive users from the whole table you could of course add a filter to the table. If you want them to be seen but without values for age you could change the IF statement to return BLANK() if status = inactive or so. Let me know if you need information!
- yaman1235 years ago
Post Partisan
I would like to show only employees who were still in the business for that month. I have start and end dates in the employee table. How would i write this in the existing measure for age or will a new measure be required?