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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Steph83
Frequent Visitor

How to calculate average age of a group of persons in XX years?

I have a group of 300 people ("Artists") for whom I have their date of birth ("date of birth").

I would like to know the average age of this group on a specific date that I would select in a dashboard filter.

In fact my data base gathered all persons, but all are not available all the time. So I need to know, among the persons who are there, at a specific date, the average age of the persons

 

Thnaks in advance for your support

Stephane

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You could create a measure like

Average age =
VAR ReferenceDate =
    SELECTEDVALUE ( 'Slicer date'[Date] )
VAR Result =
    AVERAGEX ( Artists, DATEDIFF ( Artists[Date of birth], ReferenceDate, YEAR ) )
RETURN
    Result

where 'Slicer date'[Date] is the column you are using on the slicer.

View solution in original post

5 REPLIES 5
johnt75
Super User
Super User

You could create a measure like

Average age =
VAR ReferenceDate =
    SELECTEDVALUE ( 'Slicer date'[Date] )
VAR Result =
    AVERAGEX ( Artists, DATEDIFF ( Artists[Date of birth], ReferenceDate, YEAR ) )
RETURN
    Result

where 'Slicer date'[Date] is the column you are using on the slicer.

Good day,

Something is missing. I have well the average of the list of persons at a selected date however, it gives the average of all the persons whatever the filter applied on the page (gender, above 30....). How can I include the selected filters in the formula so as to calculate the average on the selected persons only?

The code I posted should respect any filters placed on the Artists table. If it is not doing that can you post a link to a sample PBIX ?

Hi john,

Indeed, I was using two tables. Now it has been solved. Thanks

Hello John, 

When I read your proposal, it seems so easy, but I wouldn't have been able to find it!!!

That's work perfectly, thank you

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors