Logic & flow

Masking

How to narrow what a respondent sees inside a single question — show only the brands they're aware of, only the regions that matched, only the rows that survived a previous question. Driven by `options.from:` and `scale.from:` plus the collection methods `.minus()`, `.intersect()`, `.union()`, and `.add()`.

What masking is

Routing gates whole questions — show this question, hide that one. Masking is one level finer: inside a question, narrow the options, rows, or scale codes that render.

Two properties cover every case:

ToolWhere it livesWhat it narrows
options.from:A question propertyThe option list (rows on a grid, items on single / multi / rank / openList / numberList). Pulls codes from a runtime expression.
scale.from:A question propertyThe grid scale (column dimension on gridSingle / gridMulti).

options.from: — pull options from a runtime expression

options.from: takes a Python expression that returns a collection of codes. The runtime expands those codes into the question’s options at render time, drawing labels from a list / group the codes refer to.

- qid: QBrandsAware
    type: multi
    text: Which brands have you heard of?
    options: brandList

- qid: QBrandsTried
    type: multi
    text: Which of those have you tried?
    options.from: QBrandsAware.selected

QBrandsTried only shows brands the respondent picked in QBrandsAware. Pick three of seven brands first, see those three on the second question.

The labels for the resulting codes come from the original list or group those codes belong to (the runtime resolves the codes back through the survey’s - lists: block automatically).

scale.from: — same idea for grid columns

scale.from: is options.from:’s sibling for the column dimension on gridSingle and gridMulti. The scale shrinks to whatever codes the expression returns.

- qid: QStoresVisited
    type: multi
    text: Which stores have you visited?
    options: storeList

- qid: QStoreSatisfaction
    type: gridSingle
    text: How satisfied are you with each store you visited?
    options.from: QStoresVisited.selected   # rows: only stores they visited
    scale: satisfactionScale                # columns: full 5-point scale

Or trim the scale itself:

- qid: QSatisfaction
    type: gridSingle
    text: How satisfied are you?
    options: brandList
    scale: satisfactionScale
    scale.from: QSatisfaction.scale.all.minus([3])

.scale.all returns the full scale domain; subtracting code 3 (the Neutral point) gives a forced-choice 4-point scale.

The collection toolkit — .minus(), .intersect(), .union(), .add()

Inside an options.from: expression, .selected and .all are collections. Four methods reshape them:

MethodReturnsUse when
.minus(codes)The collection with codes removedExcluding specific items from a base set
.intersect(codes)Only codes in both the collection and codesRestricting to a known subset
.union(codes)The collection plus codesAdding items to a base set
.add(codes)Same shape as .union(codes) — appends codesSynonym, slightly more imperative-sounding

Each method returns a new collection, so you can chain them:

options.from: QBrand.selected.minus([99]).union([98])

Q.all (the question’s full authored domain) is the most useful starting point when you want “everything except some codes”:

options.from: QBrand.all.minus([QFavBrand.value])

QBrand.all returns every code the brand list knows; subtracting QFavBrand.value leaves every brand except the respondent’s favourite.

Common patterns

Carry-forward — show only what was picked

The most common masking pattern. Ask a broad multi-select first; narrow downstream questions to the picked subset.

- qid: QChannelsUsed
    type: multi
    text: Which channels have you used in the last month?
    options: contactChannels

- qid: QChannelSatisfaction
    type: gridSingle
    text: How satisfied are you with each one?
    options.from: QChannelsUsed.selected
    scale: satisfactionScale

Pick three channels of seven, rate those three. No noise from unused channels in the satisfaction grid.

Exclusion — show everything except a specific code

Use .minus() against the question’s full domain:

- qid: QFavBrand
    type: single
    text: Which brand is your favourite?
    options: brandList

- qid: QSecondChoice
    type: single
    text: Which would you pick if your favourite weren't available?
    options.from: QFavBrand.all.minus([QFavBrand.value])

QFavBrand.all is every brand in the list; .minus([QFavBrand.value]) removes the respondent’s favourite. The second-choice question shows everything except the one they already picked.

For multiple exclusions:

options.from: QBrand.all.minus([97, 99])     # remove "Other" and "Prefer not to say"
options.from: QBrand.all.minus(QExcluded.selected)   # remove the entire exclusion set

Restriction — keep only a known subset

Use .intersect() when you want to filter the question’s full domain (or a previous selection) down to a specific list:

- qid: QPremiumBrands
    type: multi
    text: Which premium brands have you considered?
    options.from: QBrand.all.intersect([1, 2, 3, 5, 8])

Only the five premium codes render, regardless of what the full brand list contains. If the project later adds more brands to brandList, this question stays restricted to the premium five without further authoring.

You can also intersect a respondent’s selection with a known subset:

- qid: QPremiumOwned
    type: multi
    text: Which premium brands have you owned?
    options.from: QBrandsOwned.selected.intersect([1, 2, 3, 5, 8])

Show only the brands the respondent picked and that count as premium.

Addition — add codes to an existing set

Use .union() (or .add()) when you want a previous selection plus a few extra codes — typically an Other or None option that should always render alongside the carry-forward set.

- qid: QChannelsUsed
    type: multi
    options: contactChannels

- qid: QChannelPreferred
    type: single
    text: Which channel do you prefer overall?
    options.from: QChannelsUsed.selected.union([99])

The preferred-channel question shows the channels the respondent used, plus code 99 (typically None of these or Prefer not to say) appended at the end.

Mask with a script-defined helper

When the masking logic is complex enough that an inline expression gets ugly, move it into a top-level - script: and call it from options.from:.

- script: |
    def relevant_categories():
        # Only categories with last-month spend > $50.
        result = []
        for c in QSpend.all:
            if QSpend.row(c).value > 50:
                result.append(c)
        return result

- qid: QPriorities
    type: rank
    text: Rank these spend categories by priority.
    options.from: relevant_categories()

The script runs in the flow before the question; its return value is the list of codes the question shows. The loop is written explicitly with for and append — list comprehensions aren’t supported in the Python subset, so the everyday equivalent is a loop and a list builder.

Conditional addition — extras only for some respondents

When the Other (or any extra) option should appear only under some condition, combine .union() with a Python conditional expression:

options.from: QBrand.all.union([99] if QSegment.value == "premium" else [])

Premium-segment respondents see the full brand list plus code 99; everyone else sees only the brand list. The conditional returns either [99] or [], and .union(...) of an empty list is a no-op.

For more complex add/remove logic, prefer a script helper that returns the final code set.

What masking can’t do

A few things that look like masking but aren’t:

  • Hide an entire question — that’s Routing, not masking. Masking narrows what’s inside a question; routing decides whether the question shows at all.
  • Reorder options conditionally — options.from: reorders to whatever order the source collection produced. For random / fixed orderings, use order: on the question.
  • Replace labels at runtime — masking restricts the code set, but labels come from the original list or options: map. To pipe runtime values into labels, see Piping.

See also

  • Routing — gate whole questions, pages, and blocks
  • Defining lists — author the lists options.from and scale.from resolve against
  • Collections — .minus, .intersect, .union, .add, .size, .any, .every
  • Piping — inject runtime values into question text and labels
  • Q.* accessors — what you can read in an options.from: expression