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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Chockers1
Frequent Visitor

DAX Calculate age between two dates on two different tables

Hi All,

 

I have two multiple tables on a cricket dashboard and want to work out the players age at the start of a match.

 

The first table is called "Bat" and this is what the dashboard is made up off. It has a column called start_date

 

The other table is called "PP" and that has the player profiles detials and importnatly a date called "Born". These are linked on the data table by a player ID.

 

I want to add to my dashboard using the daa from "Bat" an age calucalation essentially being - Born - Start Date and leaving just the age.

 

I've looked through heaps of forums and YT videos and cant quite work it out.

 

Really hoping someone can help.

 

Thanks

Rob

 

bat.png

1 ACCEPTED SOLUTION

@Chockers1 

Oh! Apologies for that

Average Age =
AVERAGEX (
Bat,
DATEDIFF ( MAXX ( RELATEDTABLE ( PP ), PP[Born] ), Bat[Start_Date], YEAR )
)

View solution in original post

10 REPLIES 10
Chockers1
Frequent Visitor

Thanks mate

 

The error message based on that is below

 

Sounds like the relationship isn't working?

 

error.pngrelationship.png

@Chockers1 
Please try

Average Age =
AVERAGEX (
    Bat,
    INT ( Bat[Start_Date] - MAXX ( RELATEDTABLE ( PP ), PP[Born] ) )
)

average age dax.pngaverage age.png

Thanks mate, this is what appears - is it possible to make that into how old a player is in just years?

@Chockers1 

Average Age =
AVERAGEX (
Bat,
DATEDIFF ( Bat[Start_Date], MAXX ( RELATEDTABLE ( PP ), PP[Born] ), YEAR )
)

Awesome mate, that has got it working!

 

The only thing left it shows as a minus age

 

Any ideas?age showing minus.png

@Chockers1 

Oh! Apologies for that

Average Age =
AVERAGEX (
Bat,
DATEDIFF ( MAXX ( RELATEDTABLE ( PP ), PP[Born] ), Bat[Start_Date], YEAR )
)

thank you so much works beautfully!!!

Thank you, thats the first time its got a calculation out 🙂

 

That gives me the average age, no quite what I was after.

 

I guess ideally i just want it to show the years difference between the start Date and the Born date

@Chockers1 

Please present one example 

tamerj1
Super User
Super User

Hi @Chockers1 

please try

Average Age =
AVERAGEX ( Bat, INT ( Bat[Start_Date] - RELATED ( PP[Born] ) ) )

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.