Calculations for Hidden Values
You can use a special question type called a hidden value to store values from other forms and carry out calculations without it being visible to the mobile worker. The important field is the calculate field, which you can put calculation expressions. Some common examples include:
- Age in years: int((today() - date(#form/dob)) div 365.25)
- Age in months: int((today() - date(#form/dob)) div 30.4)
- Age in weeks: int((today() - date(#form/dob)) div 7)
- Estimated Date of Delivery (EDD) from Last Menstrual Period (LMP): date(#form/lmp + 280)
- Summation of three questions: int(#form/question_one) + int(#form/question_two) + int(#form/question_three)
Display Logic for Hidden Values
- You can put a display condition in a hidden value
The hidden value will hold the null value '' until its display condition is met. Once its display condition is met, it holds the calculated or loaded value.
- If you update the case from a hidden value, it will only update the case if its display condition is met.
For further guidance on doing calculations please see Hidden Values Tutorial Part 1: Adding Two Questions Using a Hidden Value and Hidden Values Tutorial Part 2: Calculations Using a Date.
Other calculations can be found on this page.