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
lucianovazbh
Frequent Visitor

average age in year

Hello friend,
I need a big help from you!!!
I have a visual where it has a dynamic age calculation and also an age group, all of this dynamically as shown in the attached example.
I need to get the average age over the years. Example, if in 2016 there are 11 employees, and I have their age (what is the average age in that year?
I've tried everything and I couldn't.
OBS I don't want to use calculated column, it has to be measured.PBIX example 

lucianovazbh_0-1669330593274.png

 




4 REPLIES 4
TomMartens
Super User
Super User

Hey @lucianovazbh ,

 

I created this measure:

average age = 

var currentYear = CALCULATE( MAX( 'Dcalendar'[Ano] ) )
var lastDayOfCurrentYear = DATE( currentYear , 12 , 31 )
return
AVERAGEX(  
    FILTER(
        CALCULATETABLE(
            'Table'
            , ALLSELECTED( 'Table' )
        )
        , YEAR( 'Table'[Atualizacao] ) <= currentYear
    )
    , var dateOfBirth = CALCULATE( MAX( 'Table'[Nascimento] ) )
    return
    DATEDIFF( dateOfBirth , lastDayOfCurrentYear , YEAR )
) 

This allows me to create this visual:
image.png
You can see how the first employee is aging through the year 1946 - 1958, but then a 2nd employee reduces the average age.

 

Hopefully, this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

@TomMartens 
Thanks for the feedback,
Only the employee must be considered for age calculation where: a table[update]=max(table[update]) and table[Status]="N", as per the example file.xlsx.
otherwise, it must accept segmentation such as average by gender,
unfortunately I still can't solve it.
The average should be like the image below and the xlsx file.

Lucianovaz_0-1669675294519.png

Lucianovaz_1-1669675363297.png
Example XLSX 
Lucianovaz_2-1669675574434.png

 

 




TomMartens
Super User
Super User

Hey @lucianovazbh ,

 

please make access to your pbix file anonymous if I try to download the file I'm asked to request access, I will not do that.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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