Hello,
I am new to commcare and i am trying to filter filter a case list. Basically, i have Date of Visit and Age variables and i would like to add a calculated property called Current Age. Then finally filter cases using Current Age.
To calculate the Current Date , i am trying this:
int((today() - date(date_of_visit)) div 365.25) + age
Then i would like to filter case list as below:
Current Age < 5 #To list all members who are less than 5 years
What you are describing sounds like it should work, though you'd have to copy the "Current Date" expression into the filter - I don't believe you can declare a variable and reference that elsewhere in this context. That is, your filter would have to be:
int((today() - date(date_of_visit)) div 365.25) + age < 5
That does seem like a fairly roundabout way of getting the current age - have you considered storing a date of birth property and using that instead?
Thank you for helping out. I did try that expression. I created a calculated property that computed the current age using the expression above. Unfortunately, i get NaN error. It seems the date_of_visit is not read on the calculated property and yet if you add it as a property, you clearly can see the date.
My other concern is that after adding a calculated property, how do you reference to it. It doe not seem to have provision for variable name.
I'm not sure where the NaN error could be coming from. You might try breaking down that expression into each component to identify where the problem is.
That's correct - there is no provision for a variable name. You can store properties on the case (when filling out forms) and reference those, but I don't believe you can refer to calculated columns in other columns or in a case list filter.