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

Every export column name is built mechanically from the question id and the position inside the question. The rules don’t change between question types, so once you know them you can predict every column without running the survey.

  • qid — the question id you wrote in the YAML. It must match the validity rule (see Glossary → qid).
  • Position prefixes — r for row, c for column, o for option. Written inline, no separator.
  • Loop suffix — _N is appended for questions that live inside a loop, where N is the iteration number. See Loop suffixes.
Why a mechanical rule? Survey programmers and analysts need to predict the column name from the YAML alone, without running the survey. Locking the rule eliminates surprises after fielding.

Pattern by question type

Question typePatternExample
single, open, numberqidQBrand
multi (one column per option)qidoNQFeatureso1, QFeatureso2
gridSingle, gridMultiqidrN (one column per row)QSatisfr1
gridNumber with direction: rowsqidrNcMQBudgetr1c1
gridNumber with direction: colsqidcNrMQVolumec1r1
numberList, openListqidrNQSpendingr1
specify (attached text entry)qidoNSpecifyQBrando99Specify
lookup (single-step)qid, qidFieldNameQZip, QZipCity, QZipRegion
lookup (cascading step)qidStepId, qidStepIdFieldQVehicleMake, QVehicleModelBodyType
Loop iteration suffixbase_NQBudgetr1c1_3

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

See also