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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
BI-1294
Frequent Visitor

Historical average age dax

Hi all, 

I'm struggling to calculate the average historical age of the staff that was active in a certain moment. Let's say I want to see for every past month which was the staff age average of the active staff (for active staff I mean with a contract that was not ended).

This is the simplified table that I have (currently I have also 2 inactive relationships between the calendar date and end_date and start_date):

 

StaffID (key of the table - no duplicates) 

Start_Date (hiring date) 

End_Date (last day of work) 

Birth_Date

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@BI-1294 Seems like:

Measure =
  VAR __Date = MIN('Calendar'[Date]) //or max
  VAR __Table = 
    ADDCOLUMNS(
      'Table',
      "__AgeInDays" = (__Date - [Birth_Date]) * 1.
    )
RETURN
  AVERAGEX(__Table,[__AgeInDays])
  

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

@BI-1294 Seems like:

Measure =
  VAR __Date = MIN('Calendar'[Date]) //or max
  VAR __Table = 
    ADDCOLUMNS(
      'Table',
      "__AgeInDays" = (__Date - [Birth_Date]) * 1.
    )
RETURN
  AVERAGEX(__Table,[__AgeInDays])
  

Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.