Reply
jim_hubbardUIHS
Frequent Visitor
Partially syndicated - Outbound

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)

Start of Seleted QTR = SELECTEDVALUE('Dim_Dates QTRS'[Date],"1/1/2024")
End Current of quarter = EOMONTH ( [Start of Seleted QTR], 2 )
 
Here is the column
Age In Months End of Current QTR = DATEDIFF(Fact_Patient[dob],[End Current of quarter],MONTH)
 
Thanks for any insights
jim
 
 

 

 

1 ACCEPTED SOLUTION
PijushRoy
Super User
Super User

Syndicated - Outbound

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 visual

Calculate 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 




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





View solution in original post

1 REPLY 1
PijushRoy
Super User
Super User

Syndicated - Outbound

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 visual

Calculate 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 




Did I answer your question? Mark my post as a solution!
Appreciate your Like/Kudos

Proud to be a Super User!





avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)