The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi all!
Need help with a DAX code to create a calculation to find out the Customer's Age at the date of the transaction and not as per TODAY. The following is my data model:
My Customer Table and Sales Table are connected based on Customer ID and not on a Date Field.
Could you please help me out here?
Solved! Go to Solution.
Please try
Customer Age =
DATEDIFF (
RELATED ( 'Customer Lookup'[Date of Birth] ),
'Sales by Store'[Transaction Date],
YEAR
)
Age = DATEDIFF('Table'[Birthdate], 'Table'[Transaction Date],YEAR)
Thanks, @tamerj1 !🙌
This was pretty straightforward. Do you know where I messed up?
For some reason, I was trying to add a new column in the Customer's table with this formula earlier 😅😂 so wasn't getting it.
Age = DATEDIFF('Table'[Birthdate], 'Table'[Transaction Date],YEAR)
Hi @homeshagarwal
So are looking for a calculated column in the Sales table or a measure in report sliced by transaction? Do you have date of birth column for each customer or just the current age of the customer in years?
Hi @tamerj1
I'm looking to include a Calculated Column in my Sales table to specify the customers' age at the time of the transaction. Also, yes, I do have a Birthdate column in the Customer's table.
Please try
Customer Age =
DATEDIFF (
RELATED ( 'Customer Lookup'[Date of Birth] ),
'Sales by Store'[Transaction Date],
YEAR
)
User | Count |
---|---|
15 | |
13 | |
9 | |
6 | |
6 |
User | Count |
---|---|
28 | |
18 | |
13 | |
9 | |
5 |