Quantcast
Channel: SQLBI
Viewing all articles
Browse latest Browse all 434

Correct calculate of age in DAX from birthday

$
0
0

By answering to a student question I realized we often used a wrong calculation of customers age in DAX, and the simple solution is to borrow the same technique used in Excel, using INT and YEARFRAC rather than DATEDIFF or other divisions by 365 or 365.25.

The right calculation is:

Age = INT ( YEARFRAC ( Customer[Birthdate], TODAY () ) ) 

Simple and effective.


Viewing all articles
Browse latest Browse all 434

Trending Articles