Equation Question Type

Equation Question Type

Overview

The Equation question type calculates a value from earlier answers and saves it in the response — a running score, a BMI, a random group number, or a tailored sentence. It supports any syntax that ExpressionScript understands.

Three things make it special:

  • It computes even when hidden. Unlike every other question type, a hidden equation is still evaluated and its value stored in the database — which is exactly how it is usually used: as an invisible calculator.
  • It can assign values to other questions via the assignment operator.
  • No HTML is saved in the database, for security reasons.

Add and edit the question

  1. Click the + button and choose Equation from the Number group.
  2. Put your expression, in curly brackets, into the question. The cleanest way is the dedicated Equation setting in the question's settings panel — that keeps the stored value separate from the display text (and works across languages). You can then show a friendly sentence in the question text, such as "Your BMI is {self.NAOK}", while only the calculated value is saved.
  3. If the result is a number, also enable the Numbers only advanced setting, so the value is stored as a proper numeric variable for statistics and exports.

Common examples

Assume earlier questions have the codes weight, height, q1q3. Give the equation question its own code (e.g. score) so you can reuse the result later.

  • Total score: {sum(q1.NAOK, q2.NAOK, q3.NAOK)} — adds up the answers.
  • BMI: {weight / (height * height)} — the classic calculation example (a ready-made sample survey is linked below).
  • Random group (A/B test): {rand(1, 2)} — randomly stores 1 or 2. Hide the question, and each respondent is randomly assigned to group 1 or group 2.
  • Category from a value: {if(score > 10, 'High', 'Low')} — stores "High" or "Low" depending on the score.

Using the result for conditions

The stored value behaves like any other answer, which makes equations the standard trick for branching logic:

  • In the Condition designer ("New logic" in a later question's settings), reference the equation's code — for example, show a question group only when rand1 equals 1, or ask follow-up questions only when score > 10.
  • In later question text, pipe the value in with its code: {score}.

Related Resources

Download the sample survey (Limesurvey_survey_BMIsample.lss.zip) to see a working BMI calculator built with this question type.

See also Use answers from previous questions (piping) for referencing codes in text, and Mask Questions for related question types.