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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Theo_
New Member

years between dates + categories using measures only

Hi There,

 

I have been searching the forum but I can't find any posts that tackle my specific issue. I am building reports for a renting company and I and can only make measures, not calculated colums or new tables. 

 

I have the following two dimensions connected through Customer_ID:

Customer_IDBirthDate
11-1-2006
23-6-1970
324-5-1998
44-9-2008
512-2-2023

 and 

Order_IDCustomer_IDRent_StartDateRent_EndDate
117-4-202321-6-2023
2212-4-202322-6-2023
331-5-2023 
448-5-2023 
5523-5-2023 

What I am trying to do is two things: 1) calculate the customer's age in years at the start of the renting period and 2) organise these years in age-categories. With only measures. 

 

Just for context: I am already reporting the total orders (per month, based on Rent_StartDate) and I want to add the average age at the start of the rent, and the specific age groups at the start of the rent. 

So something like this:

 AprilMay
# Orders23
avgAgeCustomer  
# Customers 16-20  
# Customers 21-25  
# Customers 26-30  
# Customers >30  

 

Anyone here have an idea on how to tackle this issue?

 

Thanks!!

1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @Theo_,

 

Can you please try this:

 

1. Measure to calculate the customer's age at the start of the renting period.

Customer Age =
DATEDIFF(
    MAX('Rent'[Rent_StartDate]),
    LOOKUPVALUE('Customer'[BirthDate], 'Customer'[Customer_ID], MAX('Rent'[Customer_ID])),
    YEAR
)

2. Measure to categorize the ages into different age groups.

Age Category =
SWITCH(
    TRUE(),
    [Customer Age] >= 16 && [Customer Age] <= 20, "# Customers 16-20",
    [Customer Age] >= 21 && [Customer Age] <= 25, "# Customers 21-25",
    [Customer Age] >= 26 && [Customer Age] <= 30, "# Customers 26-30",
    [Customer Age] > 30, "# Customers >30",
    BLANK()
)

3. Total orders, average age, and count of customers per age category.

# Orders = COUNTROWS('Orders')
avgAgeCustomer = AVERAGE('Rent'[Customer Age])
# Customers 16-20 = CALCULATE(COUNTROWS('Rent'), [Age Category] = "# Customers 16-20")
# Customers 21-25 = CALCULATE(COUNTROWS('Rent'), [Age Category] = "# Customers 21-25")
# Customers 26-30 = CALCULATE(COUNTROWS('Rent'), [Age Category] = "# Customers 26-30")
# Customers >30 = CALCULATE(COUNTROWS('Rent'), [Age Category] = "# Customers >30")

 

Do not hesitate to let me know if you might need further assistance.


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

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

2 REPLIES 2
Sahir_Maharaj
Super User
Super User

Hello @Theo_,

 

Can you please try this:

 

1. Measure to calculate the customer's age at the start of the renting period.

Customer Age =
DATEDIFF(
    MAX('Rent'[Rent_StartDate]),
    LOOKUPVALUE('Customer'[BirthDate], 'Customer'[Customer_ID], MAX('Rent'[Customer_ID])),
    YEAR
)

2. Measure to categorize the ages into different age groups.

Age Category =
SWITCH(
    TRUE(),
    [Customer Age] >= 16 && [Customer Age] <= 20, "# Customers 16-20",
    [Customer Age] >= 21 && [Customer Age] <= 25, "# Customers 21-25",
    [Customer Age] >= 26 && [Customer Age] <= 30, "# Customers 26-30",
    [Customer Age] > 30, "# Customers >30",
    BLANK()
)

3. Total orders, average age, and count of customers per age category.

# Orders = COUNTROWS('Orders')
avgAgeCustomer = AVERAGE('Rent'[Customer Age])
# Customers 16-20 = CALCULATE(COUNTROWS('Rent'), [Age Category] = "# Customers 16-20")
# Customers 21-25 = CALCULATE(COUNTROWS('Rent'), [Age Category] = "# Customers 21-25")
# Customers 26-30 = CALCULATE(COUNTROWS('Rent'), [Age Category] = "# Customers 26-30")
# Customers >30 = CALCULATE(COUNTROWS('Rent'), [Age Category] = "# Customers >30")

 

Do not hesitate to let me know if you might need further assistance.


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

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ About: https://sahirmaharaj.com/about.html
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

It works, thanks!!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.