An expression
is any result that is calculated from data. Expressions can be used across the
mWater platform in text displays, tables, maps, and
conditions.
Display a calculated result inside a form
Expressions can be used to give feedback during a survey. In this example, an expression is inserted into an Instruction box to display a calculated value.
1. In the Survey Design tab, click on + Add New -> Instructions. 2. Place the cursor where the calculation should appear, then click on the fx symbol to the right of the text box.
Inserting an expression into an Instruction box
3. Select the first data field to use in the expression.
4. Hold the cursor over the data field to add an operation, such as add, subtract, multiply, or divide.
5. Click on Selectto choose the next value in the expression. Continue this process until the expression is complete. Note that mWater automatically handles math rules such as order of operations. As the expression grows, you can add terms in more than one place. Click on the x to remove a term.
6. Click on Insert to finish the expression. Our final expression in this example multiples the number of containers by the volume of each container to get the total volume consumed by the household. Then we divide by the number of people in the household to get a result in liters per capita per day (lcpd).
Expressions show up in text as blue boxes. Click on the box to edit the expression.
You can test the expression while the form is still in design mode by filling in some answers:
Use expressions to control conditions in forms
You can also use an expression to control whether a particular question or section is displayed in a survey form. For example, let's suppose that we have a special set of questions for households that are under water stress, defined as having less than the WHO recommended minimum of 20 liters per person per day. Using an expression, we can build a separate question group that only displays if that condition is met.
1. Insert the question group by clicking + Add -> Question Group.
2. Click on + Add Advanced Condition
Notice that this expression looks a little different from the one in the previous section; mWater has added "is Select..." to the end of the first term. There are also new options such as "Or", "Not," and "Is blank." This is because a condition has to evaluate whether an expression is true or not. We will get back to this in a moment, but for now, continue building the expression as before.
3. Click on Selectto choose a value that the expression will be compared to. Note that it is also possible to choose another field in the form here. Click OK.
4. Click on the word "is" that appears in front of the number 20. This allows you to choose other linking conditions. If we were to leave the word "is" then the question group would only appear if the value was exactly 20. But we want the questions to show up when the value is less than 20, so choose that instead.
5. Save the question group and add questions to it. mWater tries to summarize the condition in plain wording when the survey is viewed in Design mode.
Form calculations
Calculations can be used when the value of an expression needs to be used many times or you would like to export the value along with the other answers in the form.
1. In the Survey Design view, click on Calculations.
2. Click Add Calculation and provide a name and description for this value.
3. Click on Select to add the expression, then Save the calculation.
You can now access the Calculation result in the response popup, exported data, or even in other expressions.
For example, now we can use the new calculation to control whether the water scarcity questions appear: