I created the following Dax expression to calculate the Age
Age :=
VAR Birthdate = DIM_CUSTOMER[DATEOFBIRTH]
VAR ThisDay =TODAY ()
VAR IntBirthdate =
YEAR ( Birthdate ) * 10000
+ MONTH ( Birthdate ) * 100
+ DAY ( Birthdate )
VAR IntThisDay =
YEAR ( ThisDay ) * 10000
+ MONTH ( ThisDay ) * 100
+ DAY ( ThisDay )
VAR Age =
QUOTIENT ( IntThisDay - IntBirthdate; 10000 )
VAR CheckedAge =
DIVIDE ( Age; NOT ISBLANK ( Birthdate ) )
RETURN
CheckedAge
It seems that it work perfectly But, when I tried to Deploy the project I got the following ERROR
"Impossible de déployer les métadonnées. Raison : La syntaxe pour 'Birthdate' est incorrecte. La colonne calculée 'DIM_CUSTOMER[Age]' contient une erreur de syntaxe. Entrez une formule valide."
That's a really weird age calculation. I don't understand why you're dividing by a date for CheckedAge
.
Why not something like this?
Age := DATEDIFF ( DIM_CUSTOMER[DATEOFBIRTH], TODAY (), YEAR )
or
Age := DIVIDE ( DATEDIFF ( DIM_CUSTOMER[DATEOFBIRTH], TODAY (), DAY ), 365.25 )