Primary Keys, Codeframes & Multi-Response Variables
Three bits of structure make a data store work well with the rest of the platform. A primary key tells records apart. Codeframes give numeric codes their meaning. Multi-response variables keep “choose all that apply” questions together.
You’ll find all three on Variable View. For the basics of that tab, see Manage variables.
Primary keys
Section titled “Primary keys”The primary key is the variable that identifies each record, like a respondent ID or an order number. It must be unique (no two records share a value) and filled in on every record.
When you import or update data later, Data Wrangler uses the primary key to match incoming rows to existing records. A data store without one treats every incoming row as a new record.
Other apps need one too: Case Manager, Text Explorer and Action Connect can only use a data store that has a primary key.
Set the primary key
Section titled “Set the primary key”- Select the variable - On Variable View, tick the one variable you want as the key.
- Click Set Primary Key - It’s in the action panel. There’s no confirmation; Data Wrangler checks the data and applies the change straight away.
- Check the result - You’ll see ”’…’ is now the primary key.” and a key icon next to the variable.
Setting a new primary key replaces the old one. In Variable View, a primary key is always a single variable. To combine several columns into a key, do it when you import the file.
You can also tick Set as primary key when you add a variable, if the data store doesn’t have a key yet.
Unassign the primary key
Section titled “Unassign the primary key”Tick the current key variable and click Unassign Primary Key. It happens straight away, and you’ll see ”’…’ is no longer the primary key.”
When keys are locked
Section titled “When keys are locked”You can’t set or unassign the primary key when:
- the data store is published. The owner can unlock it with Edit Schema.
- it’s a survey data store. The key is always the survey response.
- the variable uses Wipe or Mask + retention. See Personal information.
Codeframes
Section titled “Codeframes”A codeframe maps numeric codes to labels, like 1 = “Very satisfied” and 2 = “Satisfied”. The data stores the codes; the labels are what people see in Data View with Show Labels, in exports set to Labels, and in other apps.
You can add a codeframe to an Integer or Number variable that was added in this data store (not one that came from a survey). Codeframes work on published data stores too.
In the Codeframe column, you’ll see:
- Add: no codeframe yet
- Manage: edit the existing codeframe
- View: a read-only look, for multi-response variables or if you can’t edit
- an info icon, when a codeframe isn’t possible. Hover over it to see why.
Add or edit codes one at a time
Section titled “Add or edit codes one at a time”- Click Add or Manage - The Codeframe dialog opens.
- Add an entry - Enter a Code (a number) and a Label, then click Add Entry. If you leave the label blank, the code is used.
- Edit or remove entries - Click a label to change it, or click Remove Entry to delete a code.
- Click SAVE - You’ll see “Codeframe saved successfully.” It’s saved straight away.
Paste a whole codeframe with Bulk Edit
Section titled “Paste a whole codeframe with Bulk Edit”Copying a codeframe from a questionnaire? Bulk Edit turns it into codes in seconds.
- Click Bulk Edit - In the Codeframe dialog.
- Paste one entry per line - Put the code first, then the label, for example:
The table above previews the result as you type.1 Very satisfied2 Satisfied3 Neutral
- Tidy up if needed - Tick Strip full stops if your codes look like
1.or2.. - Click SAVE.
Lines that don’t start with a number are skipped, and so are repeated codes; you’ll see how many. Click Row Edit to switch back.
Remove a codeframe
Section titled “Remove a codeframe”Click Remove in the Codeframe dialog to clear every entry, then click SAVE. You’ll see “Codeframe removed successfully.”
Multi-response variables
Section titled “Multi-response variables”A multi-response variable groups several Yes/No variables into one “choose all that apply” question. For example, q5_1 “Email”, q5_2 “Phone” and q5_3 “Chat” become a single question, “How did you contact us?”
To create a new multi-response variable from scratch, see Add a multi-response variable. To group variables you already have, use Define Multi Response.
Group existing variables
Section titled “Group existing variables”- Select the variables - On Variable View, tick two or more variables.
- Click Define Multi Response - It’s in the action panel. The Define Multi Response dialog lists “The following variables will be grouped:”.
- Name the group - Enter a Label; Data Wrangler suggests a Multi-response variable name from it. The name follows the usual naming rules.
- Click DEFINE - The group is created straight away, with your variables nested underneath it.
Data Wrangler doesn’t check what’s in the variables you group, so make sure they’re the Yes/No columns of a single question. You can’t group a variable that’s already a multi-response variable.
Ungroup a multi-response variable
Section titled “Ungroup a multi-response variable”Click Ungroup Multi-Response on the group’s row, then YES. The group is removed, and its variables go back to being separate variables. You’ll see “Multi-response variable ”…” ungrouped successfully.”
You can’t group or ungroup variables on a published data store.
On survey data stores
Section titled “On survey data stores”Survey data stores have some limits:
- The primary key is always the survey response, so you can’t change it.
- You can add codeframes to Integer and Number variables you added yourself.
- You can group and ungroup variables you added yourself, but not ones that came from the survey.
See Survey data stores.
Frequently Asked Questions
Section titled “Frequently Asked Questions”Does every data store need a primary key?
No, but it helps. Without one, every row you import later is added as a new record, so you can’t update existing records.
Can I use more than one variable as the primary key?
Only when you import a file. In Variable View, the primary key is always a single variable.
Why don’t I see Set Primary Key?
Select exactly one variable that isn’t the key already. Set Primary Key isn’t available on published or survey data stores.
Why can’t I add a codeframe?
Codeframes are only for Integer and Number variables added in this data store. Hover over the info icon in the Codeframe column to see the reason.
Can my codes be text, like “A” or “B”?
No. Codes must be numbers. Put the text in the label instead.
What’s the difference between Ungroup Multi-Response and deleting the variable?
Ungroup Multi-Response removes only the group and keeps the child variables. Deleting a multi-response variable deletes the group and all its child variables, with their data.
Common Issues and Solutions
Section titled “Common Issues and Solutions””’…’ cannot become the primary key: … value(s) appear on more than one record.”
Section titled “”’…’ cannot become the primary key: … value(s) appear on more than one record.””Some records share a value, so the variable can’t identify them uniquely. The message shows examples.
- Check the examples - Find the duplicate values in Data View.
- Choose another variable - Pick one that’s unique for every record.
- Or fix the data - Correct or remove the duplicates, then try again.
”’…’ cannot become the primary key: … record(s) have no value for it.”
Section titled “”’…’ cannot become the primary key: … record(s) have no value for it.””A primary key must have a value on every record.
- Fill the gaps - Add the missing values, or choose a variable that’s always filled in.
”’…’ cannot become the primary key yet: … record(s) are still being processed.”
Section titled “”’…’ cannot become the primary key yet: … record(s) are still being processed.””An import or other change is still running.
- Wait and retry - Give it a few minutes, click Refresh Data, then try again.
”Variables using Wipe or Mask + retention cannot be assigned as primary keys: …”
Section titled “”Variables using Wipe or Mask + retention cannot be assigned as primary keys: …””Fields whose values are erased can’t identify records.
- Choose another variable - Or change the field’s personal-information handling first. See Personal information.
”Code must be numeric” or “Code already exists”
Section titled “”Code must be numeric” or “Code already exists””Each code must be a number, and each number can only be used once. 1 and 01 count as the same code.
- Fix the code - Enter a different number.
”Codeframes can only be changed for USER-owned numeric variables.”
Section titled “”Codeframes can only be changed for USER-owned numeric variables.””The variable came from a survey or isn’t numeric.
- Use a numeric variable you added - Add an Integer variable and give it the codeframe instead.
”’…’ is already a multi-response variable and cannot be grouped again.”
Section titled “”’…’ is already a multi-response variable and cannot be grouped again.””You selected a multi-response variable along with the others.
- Change your selection - Untick the multi-response variable and try again.