Reply
alya1
Helper V
Helper V

Average age of customers by year

Hi All,

 

I have data tables like below:

All customer data including birthday and many other traits

IDBirthdayother columns...
1111/1/1995 
2222/2/2000 
3333/3/1890 
...... 


Historical customer list table showing the historical date and any ID that was an active customer on that date

IDUpload Date
1111/1/2020
2221/1/2020
1111/2/2020
2221/2/2020
3331/2/2020
...... till today

 

Calendar table with all dates from 1/1/2020 to today.

 

Relationships:

Calendar table is linked to historical table by upload date.

All customer data table is linked to historical table by ID. 

 

Is there a way to show average age of our active customers by year? Thank you!

 

1 ACCEPTED SOLUTION
gmsamborn
Super User
Super User

Hi @alya1 

 

I made up some random data and was wondering if these measures would help.

Age = 
    IF(
        MAX( 'Customer'[BirthDate] ),
        SELECTEDVALUE( 'Date'[Year] ) - YEAR( MAX( 'Customer'[BirthDate] ) )
    )


Avg Age = 
    AVERAGEX(
        ALLSELECTED( 'Historical'[ID] ),
        [Age]
    )

 

Let me know if you have any questions.

 

Avg Age.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

View solution in original post

5 REPLIES 5
gmsamborn
Super User
Super User

Hi @alya1 

 

I made up some random data and was wondering if these measures would help.

Age = 
    IF(
        MAX( 'Customer'[BirthDate] ),
        SELECTEDVALUE( 'Date'[Year] ) - YEAR( MAX( 'Customer'[BirthDate] ) )
    )


Avg Age = 
    AVERAGEX(
        ALLSELECTED( 'Historical'[ID] ),
        [Age]
    )

 

Let me know if you have any questions.

 

Avg Age.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

Hi gmsamborn, thank you very much for your reply!
I tried following along with your DAX but sadly it didn't work. I think it's because my Calendar table only have dates "from 1/1/2020 to today." So every customers age for year 2021 is 18 and 2022 is 19 and so on. Do you have any other ideas? 

Hi @alya1 

 

Is the realtionship between Historical and Customer set to both directions?

 

If that isn't the problem, can you please supply a pbix file with data that covers your problem as well as expected results from THAT data.



Proud to be a Super User!

daxformatter.com makes life EASIER!

I think that was it! Thank you so much 😄 

@alya1 

 

I'm glad I could help.



Proud to be a Super User!

daxformatter.com makes life EASIER!
avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)