> ## Documentation Index
> Fetch the complete documentation index at: https://support.deepfield-ai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a derived variable

> Define reusable categories or numbers, test their inputs, and verify the resulting values.

A derived variable calculates a value from closed-question answers. Use it to define a reusable segment or numeric result. Before you start, save the source questions and decide the result for every case, including missing inputs.

<Steps>
  <Step title="Open Variables">In **Create**, scroll to **Variables** below the questionnaire, then select **Add variable**. If the section is hidden, select **Add variable section**.</Step>
  <Step title="Choose the result type">Name the variable and choose **Categories** or **Number**. For a category result, define the categories before assigning cases.</Step>
  <Step title="Define the derivation">Enter a formula for a numeric variable. To use ordered cases, open **Variable settings → Set with rules** and define the conditions and **Otherwise** result. Category variables use rules to assign categories.</Step>
  <Step title="Test sample answers">Save the questionnaire and generate a participant test link from **Test**. Repeat the test with inputs for each case, values at boundaries, and a missing source where skipping is allowed. Compare the variable column in Responses with the expected result.</Step>
  <Step title="Save and verify">Save the questionnaire, complete a participant test, and enable the variable column in Responses. Confirm that the saved value matches the source answers.</Step>
</Steps>

<Frame caption="Annual cold-coffee spend multiplies the earlier monthly spend by 12.">
  <img src="https://mintcdn.com/deepfieldai/dK8nllvOe0f0oG_-/images/building-your-study/configured-variable.png?fit=max&auto=format&n=dK8nllvOe0f0oG_-&q=85&s=6570af1c479a120c1a2f73aacf5eb82d" alt="Saved numeric variable with a formula reading 12 times Section 1 Question 2" width="888" height="379" data-path="images/building-your-study/configured-variable.png" />
</Frame>

## Order cases deliberately

For a frequency segment, define regular cold-coffee drinkers from the saved frequency choices and use Otherwise for the remaining cases. Put more specific cases before broader cases that would also match. Do not label an unanswered source as a substantive answer without an explicit rule.

## Use the variable in the study

Select the variable where the relevant condition, piping, or analysis control offers it. Its inputs must be available before participant-facing logic uses it. Quota controls enforce their own eligibility restrictions; a variable appearing in analysis does not make it a valid quota source.

If you add a **Screening** through **Variable settings**, screening waits until the required inputs have been answered. Test both an excluded case and a case that continues.

<Frame caption="Show the source and variable together: the completed test stores 30 per month and 360 per year.">
  <img src="https://mintcdn.com/deepfieldai/dK8nllvOe0f0oG_-/images/responses/filtered-records.png?fit=max&auto=format&n=dK8nllvOe0f0oG_-&q=85&s=02beab06d04d0413cd97ac0e9e919113" alt="Filtered completed test response showing source 30, custom answer 35, and derived value 360" width="1368" height="166" data-path="images/responses/filtered-records.png" />
</Frame>

## Change a variable after collection

In Testing and live studies, open **Analysis → Analysis plan → New variable** or **Manage variables**. Review the calculation before saving. Variables referenced by live routing, screening, piping, or quotas are locked. In Draft, use the study builder.

The Plan assistant can also propose a variable. Review its definition, then select **Add to the study** or **Edit**; the proposal is not saved before your confirmation. Select a saved variable explicitly in the plan where needed.

Wait for variable calculations to finish before generation. Check existing response values and dependent charts, regenerate the plan outputs, and verify their bases.

## Related

* [Reuse earlier answers](/building-your-study/answer-piping)
* [Configure conditions and routing](/building-your-study/advanced-logic)
* [Monitor responses](/responses/monitoring-responses)
* [Build and organize charts](/analysis/charts-library)
