Forum Discussion
Calculate age based on a selected date
Hi All,
Thanks in advance for any help.
I am working on a project where we are trying to calculate the age of a person (Calculated colum) based on a selected date. Inother words, how old is this person at the end of a selected QTR.
I can make all the measures display the correct date as I select a QTR, but the calculated colum in the Fact_Person table doesn't update. It stays on the "alternative date". My assumtion is the calculated column is NOT aware of the selection change.
Here is the measure (basically)
Hi jim_hubbardUIHS
Calculated column never aware about the selected QTR in visual.
You should create a measure, then you can show the Patient wise aga in visualCalculate Age = VAR SelectedQuarterStartDate = CALCULATE( MIN('Calendar'[Date]), FILTER( 'Calendar', 'Calendar'[Quarter] = SELECTEDVALUE('Calendar'[Quarter]) && 'Calendar'[Year] = SELECTEDVALUE('Calendar'[Year]) ) ) VAR CurrentDate = IF(ISBLANK(SelectedQuarterStartDate), TODAY(), SelectedQuarterStartDate) RETURN DATEDIFF(MIN('YourTable'[DateOfBirth]), CurrentDate, MONTH)
Sample Measure code below
1 Reply
- PijushRoy
Community Champion
Hi jim_hubbardUIHS
Calculated column never aware about the selected QTR in visual.
You should create a measure, then you can show the Patient wise aga in visualCalculate Age = VAR SelectedQuarterStartDate = CALCULATE( MIN('Calendar'[Date]), FILTER( 'Calendar', 'Calendar'[Quarter] = SELECTEDVALUE('Calendar'[Quarter]) && 'Calendar'[Year] = SELECTEDVALUE('Calendar'[Year]) ) ) VAR CurrentDate = IF(ISBLANK(SelectedQuarterStartDate), TODAY(), SelectedQuarterStartDate) RETURN DATEDIFF(MIN('YourTable'[DateOfBirth]), CurrentDate, MONTH)
Sample Measure code below