---
title: Fold multiple columns
description: Convert multiple columns into rows with label-value pairs.
category: Data Transformation
tags: [fold, unpivot, melt, columns, normalize]
---

# Fold multiple columns

## Description

The **Fold Multiple Columns** activity transforms multiple column values into a key-value format. It converts wide-form data (multiple columns) into long-form data (rows), where each selected column becomes a row entry with two new fields: one for the original column name (label) and another for the value.

> **Use Case**  
> This is useful when reshaping data for charting, normalization, or when preparing data for machine learning models that expect long-form inputs.

---

## Input

| Type | Description                            |
| ---- | -------------------------------------- |
| Data | Dataset with multiple columns to fold. |

---

## Output

| Type             | Description                                                  |
| ---------------- | ------------------------------------------------------------ |
| Transformed Data | Dataset with folded columns converted into row-based values. |

---

## Configuration Fields

| Field Name           | Required                      | Description                                                                   |
| -------------------- | ----------------------------- | ----------------------------------------------------------------------------- |
| **UseRegex**         | No                            | Enable to match columns dynamically using a regular expression.               |
| **Pattern To Match** | Conditional                   | Regex pattern to match column names. Visible only if **UseRegex** is enabled. |
| **Columns To Fold**  | Yes (if UseRegex is disabled) | List of specific columns to fold.                                             |
| **Folded Column**    | Yes                           | Name of the new column that stores the original column names (labels).        |
| **Values Column**    | Yes                           | Name of the new column that stores the values from the folded columns.        |

---

## Sample Input

| ID  | Name  | Q1  | Q2  | Q3  |
| --- | ----- | --- | --- | --- |
| 1   | Alice | Yes | No  | Yes |
| 2   | Bob   | No  | Yes | No  |

---

## Sample Configuration

| Field           | Value        |
| --------------- | ------------ |
| Columns To Fold | `Q1, Q2, Q3` |
| Folded Column   | `Question`   |
| Values Column   | `Response`   |

<!-- ![alt text](fold-multiple-columns-img.png) -->

---

## Sample Output

| ID  | Name  | Question | Response |
| --- | ----- | -------- | -------- |
| 1   | Alice | Q1       | Yes      |
| 1   | Alice | Q2       | No       |
| 1   | Alice | Q3       | Yes      |
| 2   | Bob   | Q1       | No       |
| 2   | Bob   | Q2       | Yes      |
| 2   | Bob   | Q3       | No       |

---
