Forum Discussion
Calculate Age column
- Anonymous2 years ago
Hi Qasim_Jan
FreemanZ Thanks for your sharing!
In response to your question, here are some details I provided:
Here's some dummy data
"Table"
Create a measure. Calculate age from the "Birth" date column and the "Today" date column.
Age = var _birthdate = SELECTEDVALUE('Table'[birthdate]) var _today = SELECTEDVALUE('Table'[Today]) var _year = DATEDIFF(_birthdate, _today, YEAR) RETURN IF( MONTH(_birthdate) <> MONTH(_today) || DAY(_birthdate) > DAY(_today), _year - 1, _year ) & " Year " & IF( MONTH(_birthdate) <> MONTH(_today) && DAY(_birthdate) < DAY(_today), 12 - MONTH(_birthdate) + MONTH(_today), IF( DAY(_birthdate) > DAY(_today), 11 - MONTH(_birthdate) + MONTH(_today), 0 ) ) & " Month " & IF( DAY(_birthdate) < DAY(_today), DAY(_today) - DAY(_birthdate), DAY(EOMONTH(_birthdate, 0)) - DAY(_birthdate) + DAY(_today) -2 ) & " Day"Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Qasim_Jan
FreemanZ Thanks for your sharing!
In response to your question, here are some details I provided:
Here's some dummy data
"Table"
Create a measure. Calculate age from the "Birth" date column and the "Today" date column.
Age =
var _birthdate = SELECTEDVALUE('Table'[birthdate])
var _today = SELECTEDVALUE('Table'[Today])
var _year = DATEDIFF(_birthdate, _today, YEAR)
RETURN
IF(
MONTH(_birthdate) <> MONTH(_today) || DAY(_birthdate) > DAY(_today),
_year - 1,
_year
)
& " Year " &
IF(
MONTH(_birthdate) <> MONTH(_today) && DAY(_birthdate) < DAY(_today),
12 - MONTH(_birthdate) + MONTH(_today),
IF(
DAY(_birthdate) > DAY(_today),
11 - MONTH(_birthdate) + MONTH(_today),
0
)
)
& " Month " &
IF(
DAY(_birthdate) < DAY(_today),
DAY(_today) - DAY(_birthdate),
DAY(EOMONTH(_birthdate, 0)) - DAY(_birthdate) + DAY(_today) -2
)
& " Day"
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.