You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/calculations_xls.md
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Adding calculations in XLSForm
2
2
3
-
Calculations can be used inside your form to derive new variables, build advanced form logic, and display results to respondents during collection.
3
+
Calculations can be used inside your form to derive new variables, build advanced form logic, and display results to respondents during data collection.
4
4
5
5
Calculations are processed within the form, helping save time during data analysis. The results are stored as new columns in the final dataset and can be used throughout the form to apply [skip logic](https://support.kobotoolbox.org/skip_logic_xls.html), set [constraints](https://support.kobotoolbox.org/constraints_xls.html), or display [dynamic content](https://support.kobotoolbox.org/form_logic_xls.html#question-referencing) in question labels and notes.
6
6
@@ -40,7 +40,7 @@ To refer to the calculation output in the rest of your form (e.g., inside a note
40
40
41
41
Calculations in XLSForm can range from simple arithmetic calculations to advanced derivation of variables.
42
42
43
-
Arithmetic **calculations** allow you to perform basic calculations using the following **operators**:
43
+
Arithmetic calculations allow you to perform basic calculations using the following **operators**:
44
44
45
45
| Operator | Description |
46
46
|:----------|:-------------|
@@ -50,14 +50,16 @@ Arithmetic **calculations** allow you to perform basic calculations using the fo
50
50
| <strong>div</strong> | Division |
51
51
| <strong>mod</strong> | Modulo (calculates the remainder of a division) |
52
52
53
-
Calculations in XLSForm follow the **BODMAS** rule for the order of mathematical operations: **B**rackets, **O**rder of powers, **D**ivision, **M**ultiplication, **A**ddition, and **S**ubtraction. This means that calculations within brackets are performed first, followed by powers, then divisions, multiplications, and so on. Using brackets (also known as parentheses) correctly ensures that your calculations function as expected.
53
+
Calculations in XLSForm follow the **BODMAS** rule for the order of mathematical operations: **B**rackets, **O**rder of powers, **D**ivision, **M**ultiplication, **A**ddition, and **S**ubtraction. This means that calculations within brackets (or parentheses) are performed first, followed by powers, then divisions, multiplications, and so on. Using brackets correctly ensures that your calculations function as expected.
54
54
55
55
## Advanced calculations
56
56
57
-
Advanced calculations in XLSForm often rely on **functions** and **regular expressions** to make calculations more efficient. [Functions](https://support.kobotoolbox.org/functions_xls.html) are predefined operations used to automatically perform complex tasks like rounding values, calculating powers, or extracting the current date. [Regular expressions](https://support.kobotoolbox.org/restrict_responses.html) (regex) are search patterns used to match specific characters within a string of text.
57
+
Advanced calculations in XLSForm often rely on **functions** and **regular expressions** to make calculations more efficient.
58
+
***Functions** are predefined operations used to automatically perform complex tasks like rounding values, calculating powers, or extracting the current date.
59
+
***Regular expressions (regex)** are search patterns used to match specific characters within a string of text.
58
60
59
61
<pclass="note">
60
-
For a comprehensive list of functions available in XLSForm, see <ahref="https://support.kobotoolbox.org/functions_xls.html">Using functions in XLSForm</a>.
62
+
For a comprehensive list of functions available in XLSForm, see <ahref="https://support.kobotoolbox.org/functions_xls.html">Using functions in XLSForm</a>. To learn more about regular expressions, see <ahref="https://support.kobotoolbox.org/restrict_responses.html">Restricting text responses with regular expressions</a>.
61
63
</p>
62
64
63
65
Examples of more advanced calculations include:
@@ -142,8 +144,5 @@ Expressions are re-evaluated when:
142
144
<li>A repeat group is added or deleted</li>
143
145
<li>A form is saved or finalized</li>
144
146
</ul>
145
-
To control when an expression is evaluated, set a <ahref="https://support.kobotoolbox.org/question_options_xls.html#additional-question-options">trigger</a> to evaluate it only when a given question is answered, or the function `once()` to ensure the expression is only evaluated once (e.g., <code>once(random())</code> or <code>once(today())</code>).
147
+
To control when an expression is evaluated, set a <ahref="https://support.kobotoolbox.org/question_options_xls.html#additional-question-options">trigger</a> to evaluate it only when a given question is answered, or the function <code>once()</code> to ensure the expression is only evaluated once (e.g., <code>once(random())</code> or <code>once(today())</code>).
0 commit comments