Vibha's data and monitoring platform · vibha.org

Rules and calculations

Think of a rule as unlocking a spreadsheet's = formulas inside your form. A spreadsheet cell can compute itself from other cells instead of someone typing the sum by hand — a rule does the same for a question: compute its value from other answers, show it only when relevant, require it only when the situation calls for it, or refuse a combination of answers that cannot both be true. Every rule is assembled visually in the rule editor, with nothing to type, and is checked in full the moment you publish — the two pages after this one cover the complete operator set and walk through several rules line by line.

The four rule kinds

Every rule you write is exactly one of four kinds, and knowing which one you need usually makes the rest of the rule obvious. In everyday terms:

  • Calculate — do the arithmetic for the respondent, the way a spreadsheet cell fills itself in instead of someone doing the sum by hand.
  • Show — only ask a question when it is actually relevant, instead of showing every question to every respondent regardless of their situation.
  • Require — only insist on an answer when the situation calls for it, rather than marking something mandatory for everyone.
  • Validate — catch a pair of answers that cannot both be true at once — an end date before a start date, say — and refuse to accept the submission until it is fixed.

The four cards below are the actual rule editor screen, each filled in with a real, working example of its kind:

How expressions work

Read a rule's formula the way you would read a spreadsheet formula like =B2*C2: some parts are plain values you typed in yourself, some are references to other cells, and some are operations combining them. An expression in the rule editor is built the same way — you assemble it by clicking rather than typing — out of four kinds of piece:

Node typeWhat it isExample
LiteralA constant value you type in. Can be text, a number, true/false, or a list."Male", 18, true, ["a","b"]
FieldThe current answer to a question on this form, addressed by the question's key.date_of_birth, school_name
Cross-form referenceAn answer from another form for the same record (record-type forms only). Resolved before evaluation — the interpreter never touches a database.registration@latest.district
OperationApplication of a built-in operator to one or more inputs.yearsBetween(date_of_birth, today())

What counts as true

Show, Require, and Validate all boil an expression down to a single yes-or-no answer — like a traffic light that is only ever red or green, never something in between. Most of the time this matches what you would already expect, with one exception worth knowing about:

ValueTreated as
trueTrue
false, null (blank), "" (empty text), [] (empty list)False
0True — the number zero is a real answer, not the same as unanswered
Any non-empty stringTrue
Any non-empty listTrue
Any non-zero numberTrue

Rules vs. conditional logic

Think of Conditional Logic as the basic calculator built into your phone, and Rules as a full spreadsheet: the calculator handles the everyday case fast, and the spreadsheet handles everything the calculator cannot. The builder gives you both, and they are not duplicates of each other — each is the right tool for a different job.

CapabilityConditional logicRules
Show / hide a questionYesYes — Show kind
Skip to a pageYesNo
Calculated fieldsNoYes — Calculate kind
Conditional requirementNoYes — Require kind
Cross-field validationNoYes — Validate kind
Date arithmeticNoYes
Dropdown list lookupsNoYes
Cross-form referencesNoYes
Nesting depthOne conditionUp to 24 levels

Use Conditional Logic for simple “if the answer is X, show Y” cases and for page-jump navigation. Use Rules when you need calculations, nested conditions, date arithmetic, lookups, or cross-form data.

Go deeper

Frequently asked questions

Where do form rules run?
In the browser as someone fills in the form, and again on the API when the response is submitted, so an invalid answer cannot slip through.
Do I need to write code to add a rule?
No. Rules are set up by choosing options in the builder.