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

Calculating age based on Date of birth for current and previous years.

Hi All,

I need to calculate Age based on Date of birth("DOB") column, but it should change dynamically if we make a selection for any previous "Fiscal year" or "Fiscal month" in Qlik sense.

Looking forward to your suggestions.

 


Thanks & Regards,

Manmeet Dhawan

7 Replies
G3S
Creator III
Creator III

Can you please provide screenshot/ example of expected output?

Mark_Little
Luminary
Luminary

HI @Manmeet 

Try something like 

IF(GetFieldSelections("Fiscal year") = 0 AND GetFieldSelections("Fiscal month") = 0,

Today() - "DOB",

DATE( '01/'&GetFieldSelections("Fiscal month")&'/'& GetFieldSelections("Fiscal year")) - "DOB"

)

Probably have to play with the date section to get the date formatted correctly 

Manmeet
Contributor III
Contributor III
Author

Hi Thanks for the response,

So, the expected output is like if my current age is 26.5(26 years 5 months) as on current year and month, I should get the same as my age in the "Age"  column, But it should change as per the selection of  previous year /month.

Ex: for 2020 same month if i check it should provide age as on that year/month i.e. 24.5 .

 

I hope i was able to explain it properly.

 

Manmeet
Contributor III
Contributor III
Author

Thanks for your response, Trying to implement this logic not getting any result...

Can you please explain it with the help of a screenshot??

 

PrashantSangle

Hello,

 

Use age() in your expression.

try like age(date(max(your_date_field)),date_of_birth_field)

 

Regards,

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Manmeet
Contributor III
Contributor III
Author

Thanks for your response,Using the above code also is not giving the correct results, I'm currently using below code to calculate age, it calculates correct for current year, But doesn't change when we select any other year/ month. 

Num((Interval(date(Date#(today(),'MM/DD/YYYY'),'MM/DD/YYYY')
-Date(Date#(DOB,'MM/DD/YYYY'),'MM/DD/YYYY'),'DD')/365),'#,##.00')
as Age;

 

Kindly suggest.

PrashantSangle

Hi,

 

which datefield you are using to select date & year?

It will not gave you the answer which you are looking for because you are doing

today - DOB

You have to do datefield(which_you_are_selecting) - DOB

 

Also, can you explain what is wrong you are getting with my above solution. Only by saying it is not giving correct result won't help us to understand the issue.

 

Regards,

Prashant Sangle

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂