Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
jim_hubbardUIHS
Frequent Visitor

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

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

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!





Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.