Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
dataaanana
Frequent Visitor

Modifying DAX Formula for Age Calculation to Include Active Employees Hired Before the Selected Year

I used the DAX formula below to create a list of active employees with their corresponding ages based on the latest year available from my Year visual filter using Between style for my slicer.

Age Measure =
VAR _selyear =
    MAX(_Calendar[Year])
VAR _selbirthdate =
    SELECTEDVALUE(hr_coredata[DOB])
VAR _age =
    DATEDIFF(_selbirthdate,DATE(_selyear, 12, 31 ), YEAR )
RETURN
_age

How can I achieve the same results if I used the dropdown style that only allows a single selection. Currently, if I choose a single year, I will only get the list of active employees hired from the year, ignoring any active employees that are hired from previous year. 

I have a calendar table and an hr_coredata table have the following columns -- [Employee_Name], [DOB] for birthdate, and [DateofHire] for reference. Thank you!



1 ACCEPTED SOLUTION
sjoerdvn
Super User
Super User

Looks like you have an active relationship between Calender and  hr_coredata[DateofHire]. You want to include all employees hired before the end of the selection year. I suggest changing the measure like this:

 

Age Measure =
VAR _selyear =
    MAX(_Calendar[Year])
VAR _age =
    CALCULATE(
        DATEDIFF(SELECTEDVALUE(hr_coredata[DOB]),DATE(_selyear, 12, 31 ), YEAR ), 
        ALL(_Calendar),_Calendar[Year]<=_selyear)
RETURN
_age

 

View solution in original post

1 REPLY 1
sjoerdvn
Super User
Super User

Looks like you have an active relationship between Calender and  hr_coredata[DateofHire]. You want to include all employees hired before the end of the selection year. I suggest changing the measure like this:

 

Age Measure =
VAR _selyear =
    MAX(_Calendar[Year])
VAR _age =
    CALCULATE(
        DATEDIFF(SELECTEDVALUE(hr_coredata[DOB]),DATE(_selyear, 12, 31 ), YEAR ), 
        ALL(_Calendar),_Calendar[Year]<=_selyear)
RETURN
_age

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.