Export reference

Export column naming

How Fieldbase builds column names in the export. The convention is mechanical — same input, same output, every time — so you can predict the column from the YAML alone.

Core rules

Four rules produce every column name mechanically from the YAML alone. Once you know them, you can predict any column without running the survey — no execution needed.

1. qid is alphanumeric only — no underscores, no hyphens, no dots. Must match /^[A-Za-z][A-Za-z0-9]+$/. Valid: Q1, QBrand, QBrandUsage, Awareness. Invalid: Q_brand, Q-brand, Q.brand. The DSL parser rejects the invalid forms at compile time — hard constraint, not recommendation.

2. Underscore is reserved exclusively for the loop iteration suffix. An underscore appears in an export variable name only as the separator between the name body and the loop iteration code at the very end — Q1r1_3. Row codes, option codes, and column codes are separated from each other and from the qid by their structural prefix letter, not by underscores. See Loop suffixes for the full story.

3. Structural prefixes identify the axis inline. Three prefix letters, written directly adjacent (no separator before or after): r = row code, c = column code (gridNumber only), o = option code (multi, rank, gridMulti scale). A trailing code with no prefix is a loop iteration code.

4. Specify is a camelCase suffix on the variable name — Q1o99Specify for the specify text of option code 99, Q1r99Specify for row code 99. No underscore before it (that would look like a loop with iteration code specify).

Why mechanical rules? Analysts and export processors need to predict column names from the YAML without running the survey. The four rules lock the shape so str.split('_') always gives the body and the optional loop code — nothing else, no edge cases.
Header shape changed in v3.8.0 (⚠ breaking). Prior to v3.8.0, some header fragments used underscore-separated codes (Q1_r1_o2). Since v3.8.0 the entire header set is camelCase-with-prefixes (Q1r1o2) and the underscore is reserved for the loop suffix alone. Snake-case columns from a legacy fielding will not line up with the current export — regenerate them from the same source data if you need the new shape.

Pattern by question type

Question typePatternExample
single, open, numberqidQBrand
multi (one column per option)qidoNQFeatureso1, QFeatureso2
rank (one column per rank position)qidoN = rank of code NQTop3o1, QTop3o2
gridSingle, gridMultiqidrN (one column per row)QSatisfr1
gridNumber with direction: rowsqidrNcMQBudgetr1c1
gridNumber with direction: colsqidcNrMQVolumec1r1
numberList, openListqidrNQSpendingr1
specify (attached text entry)qidoNSpecifyQBrando99Specify, QSatisfr1Specify
lookup (single-step)qid, qidFieldNameQZip, QZipCity, QZipRegion
lookup (cascading step)qidStepId, qidStepIdFieldQVehicleMake, QVehicleModelBodyType
lookup (multi-select)qidoN (chip N’s value) + qidFieldNameoN for fieldsQSpecialtieso1, QSpecialtieso1Area
cardSort (item → slot)qidsN = slot N contents; qidoNSlot = which slot option N landed inQSort_1s1, QSorto1Slot
textAnnotationqidwN (per-word mark) + qidTrace (JSON annotation blob)QReactw1, QReactTrace
imageAnnotation (pin / rect)qidTrace (JSON) + qidCount + qidPosCount/qidNegCountQPackTrace, QPackCount, QPackPosCount
videoAnnotation (dial / reaction)qidtN = trace value at second NQAdt1, QAdt2, … QAdt30
CBC / MaxDiff summary punchqidVersion, qidNtasksQCbcVersion, QCbcNtasks
CBC / MaxDiff per-task detailShips in the long companion, not the wide filecbc_long, maxdiff_long
Loop iteration suffix (any of the above)base_NQBudgetr1c1_3
v3.8.0 added first-class export shapes for annotation, lookup, and cardSort. Pre-v3.8.0 these types stored answers as opaque JSON blobs — QPackAnnotations = a single unwieldy text column. Since v3.8.0 they materialize into typed columns following the rules above, so analysts can crosstab and pivot on them like any other punch. The JSON Trace columns are still present for tools that want the raw geometry.

The gridNumber direction rule

gridNumber is the only question type whose column naming depends on a property — direction.

  • direction: rows — totals shown per row → columns named qidrNcM
  • direction: cols — totals shown per column → columns named qidcNrM

Pick the direction that matches how the analyst wants to sum. Switching it later renames every column in the export.

Tri-state for coded options

When a question has coded options that fan out into one column per code (multi, gridMulti), the column doesn’t store a simple 1/0. It stores a tri-state:

ValueMeaning
1The option was shown to the respondent and selected.
0The option was shown to the respondent and not selected.
nullThe option was not shown — masked by options.from, scale.from, or skipped via if.

This distinction matters whenever you mask options at runtime. A null means “they never saw this choice”, which is very different from “they saw it and rejected it”. See Tri-state projection for the full treatment.

Building a column name in Python

For analysis code or export-validation scripts, this is the exact rule expressed as a function:

import re

def format_col(qid, row=None, col=None, option=None,
               field=None, loop=None, direction='rows'):
    """Build an export column name from its components."""
    name = qid
    if direction == 'rows':
        if row is not None:    name += f'r{row}'
        if col is not None:    name += f'c{col}'
    else:
        if col is not None:    name += f'c{col}'
        if row is not None:    name += f'r{row}'
    if option is not None:     name += f'o{option}'
    if field:                  name += field[0].upper() + field[1:]
    if loop is not None:       name += f'_{loop}'
    return name

The leading record column

Every wide export starts with a record column — a persisted, monotonically-increasing case number assigned to each respondent at interview start. It’s stable across resubmits, deletes, and re-exports of the same fielding. Use it as the analyst-facing case identifier — the primary key for joins between the wide file, the long companions, and any custom overlays.

respondentId (a UUID) is also in the file, but record is the number analysts actually cite (“respondent 47 has a data-quality issue”). See Data Hub → Data View for the edit surface that operates on records.

What’s not a column

  • Isolate opt-outs emit a single flag column — when an isolate: True option (e.g. “I don’t know” / “None of these”) is active, the question’s normal row / option / cell columns go null and one flag column is added: <qid>r<code> for row-shaped types, <qid>o<code> for rank, <qid>c<code> for a gridNumber column axis, or <parent>r<code> for mixGrid. The flag reads 1 when the opt-out is active. No per-row isolate columns are ever added — just the one flag per opt-out entry.
  • info questions have no answer → no column.
  • Comments (#, #[[ … #]], trailing #) are Python-inert everywhere and never touch the export. See Python essentials → Comments.

See also