Unnest
One cell holds three answers. Unnest turns that cell into three rows.
What it does
Some columns pack many values into one cell. Survey answers, product tags, and skill lists often look like this.
Unnest cuts the cell at a delimiter. It then writes one row for each piece. The other columns repeat on every new row.
Before
| response_id | city | topics |
|---|---|---|
| 1 | Bengaluru | traffic,parks,water |
| 2 | Chennai | buses |
After, split on a comma
| response_id | city | topics |
|---|---|---|
| 1 | Bengaluru | traffic |
| 1 | Bengaluru | parks |
| 1 | Bengaluru | water |
| 2 | Chennai | buses |
Two rows became four. Now you can count each topic, or filter on one topic.
Split a column into rows
- Type unnest in the Search transforms box, in the Pipeline panel.
- Select Unnest in the results.
- Open Select column. Search for the column and click it.
- Type the separator in the Delimiter box. Use
,for a comma. - Click Apply.
The step appears in your pipeline with edit and delete buttons.
Things to know
- An empty Delimiter box means a comma. Type the character when your file uses
;or|. - The delimiter can be more than one character. A value such as
-works. - A row with an empty cell in that column disappears. There is nothing to split.
- The column keeps its position in the grid.
- Spaces stay. The value
traffic, parksgivesparkswith a leading space.
Tips
- Run Text Transform with trim after Unnest. That removes the leading spaces.
- Want columns instead of rows? Use Split Column.
- Group the result with Group & Aggregate to count each value.
For SQL users
Unnesting topics on a comma runs as:
SELECT "response_id", "city", UNNEST(STRING_SPLIT("topics", ',')) AS "topics" FROM "survey"
Try Unnest with sample data →
Related Operations
- Join - Join with another file/table
- Fill Missing - Fill null values
- JSON Extract - Extract data in JSON format into columns