# Relevant

The relevance column is used to control when a question or group should be shown, based on the user's previous answers. In ngSurvey these will be concerted to skip logic groups and rules.

A question will only be displayed if the relevance condition is true.

## 📏 How to write relevance conditions

To reference a previous question’s answer, you use the format:

`${variablename}`

This inserts the answer value from the question with the name `variablename`.

You can then build a condition using logical expressions like:

* `${age} >= 18`
* `selected(${gender}, 'female')`
* `${consent} = 'yes'`

Relevance expressions must return true for the question to appear.

## 🕵 Relevance in groups

You can apply relevance to a group as a whole:

* If the group uses appearance: field-list, the entire page of questions will be shown or hidden together.
* If the group has no appearance  then relevance can be set individually on each row inside the group for more detailed skip logic.

This allows for flexible layouts, where entire pages or individual sub-questions can be conditionally displayed.

## Examples

| Question Name | Relevance Expression          | Description                               |
| ------------- | ----------------------------- | ----------------------------------------- |
| age           |                               | A numeric input (used by others)          |
| gender        |                               | A select\_one input                       |
| school        | ${age} >= 18                  | Show only if respondent is 18 or older    |
| pregnant      | selected(${gender}, 'female') | Show only if respondent selected 'female' |
| job\_title    | ${consent} = 'yes'            | Show only if respondent gave consent      |

## 🔢 Operators and Functions

These are the operators you can use to build your logic.

#### Comparison Operators

These compare values:

| Operator | Meaning                  | Example               |
| -------- | ------------------------ | --------------------- |
| =        | equal to                 | `${age} = 18`         |
| !=       | not equal to             | `${gender} != 'male'` |
| >        | greater than             | `${age} > 25`         |
| <        | less than                | `${score} < 60`       |
| >=       | greater than or equal to | `${age} >= 18`        |
| <=       | less than or equal to    | `${score} <= 100`     |

***

#### Logical Operators

These help you combine conditions:

| Operator | Meaning            | Example                                       |
| -------- | ------------------ | --------------------------------------------- |
| and      | both must be true  | `${age} >= 18 and ${consent} = 'yes'`         |
| or       | either can be true | `${gender} = 'female' or ${gender} = 'other'` |
| not()    | opposite of true   | `not(selected(${gender}, 'female'))`          |

***

#### Selection Functions

Used mostly with `select_one` and `select_multiple` questions.

| Function   | Description                   | Example                         |
| ---------- | ----------------------------- | ------------------------------- |
| selected() | Checks if a value is selected | `selected(${gender}, 'female')` |

***

#### Date and Time Functions

| Function | Description                   | Example                    |
| -------- | ----------------------------- | -------------------------- |
| today()  | Returns current date          | `${birthdate} <= today()`  |
| now()    | Returns current date and time | `${checkin_time} <= now()` |
|          |                               |                            |
