Write expression to define age range

Hi all, I need to write a calculation to assign a weighting value for persons born between 2002 -1955. How is this done?

Hi @scherrie,

Could you kindly provide more information (maybe pictorially) on what you intend to do so that users from the community should be able to understand more clearly.

Have a great day!

I don’t really have a pictorial, but I will send the xls sheet.

Setting age range scoring.xlsx (23.2 KB)

Row 33 of the spreadsheet I have a calculation that any main applicant that is below 65, 2 points will be scored. I want to be able to set the range (constraint) where anyone who is between the ages of 18 (January 1 2002) and 65(January 1 1955) will score 2 points.

This calculation will then be added to the calculate Tier 1 scoring. (see row 156).

1 Like

Hi @scherrie,

So based on your query i have made a workaround. Please have a look at the images shared below:

In the survey tab of your xlsform:

Data entry screen as seen in Enketo: Scenario with age less then 18 years old

Data entry screen as seen in Enketo: Scenario with age within the range 18-65 years old

Data entry screen as seen in Enketo: Scenario with age greater then 65 years old

Reference xlsform:
Age Weight.xlsx (9.7 KB)

Have a great day!

1 Like

Thanks Kal, if I wanted it to round to 2 decimal places, just keep the 2 instead of inputting 0? I am asking because in the event later on in the survey I ask age for the member of the household, and they are below 1 year old, I do not want 0 to appear.

1 Like

Hi @scherrie,

If this is your requirement, you could type is as round(((${DOI}-${DOB}) div 365),2). No worries!

Have a great day!

1 Like

Thanks you have a great day as well!

1 Like