# Unpivot Table

<figure><img src="/files/nFK6VFPF8db2nnVeU9kV" alt=""><figcaption></figcaption></figure>

The **Unpivot Table** task in **Gaio DataOS** allows you to transform a wide-format table (with multiple columns representing categories or dates) into a long-format table (where values are stacked into rows). This is especially useful for time series, monthly reports, and dashboards requiring dynamic filtering.

{% hint style="warning" %}
**Important:** This task can only be used when a **table is selected** in the flow.
{% endhint %}

***

## How to Use

### **1. Open the Unpivot Table Task**

* Go to the menu:\
  **Tasks > ETL > Unpivot Table**

***

### **2. Set Task Information**

* **Task label**: (optional) Name for identifying this step in your flow.
* **Result table**: Enter the name of the new table that will contain the unpivoted data (e.g., `unpivot_table`).

***

### **3. Select Unpivot Columns**

* **Unpivot columns**: Select the columns whose values will be transformed into rows (e.g., `January`, `February`).
* These columns will become the values in a new "category" field, and their corresponding values will move into a single “quantity” column.

***

### **4. Sort Values (Optional)**

* **Sort values**: Choose `Ascending` or `Descending` if you want to control the order of unpivoted rows by column category.

***

### **5. Add Extra Columns (Optional)**

* **Extra columns**: Select columns that should remain unchanged and be repeated in the resulting unpivoted table (e.g., `Region`, `Product`).
* **Position of extra columns**: Choose whether they appear `At start` or `At end` of the result.

***

### **6. Save and Run**

* Click **Save** to store the task in your flow.
* Click **Run** to execute the task in your flow.&#x20;

***

#### Best Practices

* Use **clear numeric fields** (e.g., `valor`, `quantidade`) as the "Value to pivot" to avoid confusion in the resulting `quantity` column.
* Ensure your **column names are correct** — in the screenshot, `Novemvro` should be corrected to `Novembro`.
* Always preview the output and validate if your new table preserves the desired relationships.

***

#### Use Cases

* Convert monthly sales columns into a time series
* Normalize survey responses or data from spreadsheets
* Simplify data structure for dashboards and filtering
* Prepare wide-format datasets for analytical models

***

#### Example Output

<figure><img src="/files/swZJXxhbE5wlZsfS56Ld" alt="" width="563"><figcaption></figcaption></figure>

Given the configuration shown in the screenshot, the output table will include:

| Tipo       | category | quantity    |
| ---------- | -------- | ----------- |
| Pay        | December | 313088.1023 |
| Pay        | January  | 0           |
| Pay        | February | 0           |
| ...        | ...      | ...         |
| to receive | October  | 268242.7913 |
| to receive | November | 293688.738  |

Where:

* `Tipo` is preserved as an **extra column**
* `category` was generated from the selected **month columns**
* `quantity` holds the original values


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gaiodataos.com/tools/tasks/etl/unpivot-table.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
