# Pivot column

## Pivot column

The Pivot Column option helps you restructure your data for better analysis and easier comparisons. Pivoting data essentially means converting row values from one column into multiple columns. To demonstrate pivoting data, let's take the region-wise sales for home appliances as an example.

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(2528).png" alt=""><figcaption><p>Sample data</p></figcaption></figure>

We've pivoted the tabular data above based on the PRODUCT column. Notice how the product column has been converted into multiple columns - Microwave, Refrigerator, and Coffee Machines.

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(2529).png" alt=""><figcaption><p>Pivoted data based on the product field</p></figcaption></figure>

Let's see how we can pivot columns in Infobridge. The sample table contains country, product, and market data. We'll pivot the "Product" dimension.

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(69).png" alt=""><figcaption><p>Sample query to pivot data</p></figcaption></figure>

Select "Product" from the **Category** dropdown. We'll leave default options for the **Operations** and **Values** fields unchanged.

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(70).png" alt=""><figcaption><p>Pivot column configuration</p></figcaption></figure>

Notice how each product is now a separate column.

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(72).png" alt=""><figcaption><p>Pivoted column based on the product dimension</p></figcaption></figure>

We can choose different aggregation types like average, minimum, or maximum when we pivot a column as shown below

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(80).png" alt=""><figcaption><p>Other aggregation types</p></figcaption></figure>

## Unpivot column

Unpivot does the opposite of pivot - it converts multiple column dimensions into a single row dimension. Let's consider the Product example - the sales for each product is captured in a separate column.

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(73).png" alt=""><figcaption><p>Sales for each product is in a separate column</p></figcaption></figure>

Click on the **Unpivot** option from the Transform ribbon. Select the columns to be unpivoted into rows from the Column dropdown. We've selected all the product columns.

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(74).png" alt=""><figcaption><p>Unpivot columns</p></figcaption></figure>

When you click Apply, each product column is converted into a single column titled "Attribute" that contains all the products as multiple rows. The sales for each product is also converted into a single column titled "Value" with multiple rows corresponding to each product.

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(75).png" alt=""><figcaption><p>Unpivoted data for the product columns</p></figcaption></figure>

Finally let's use the **Rename Column** button to change the name of the default "Attribute" and "Value" columns to relevant, meaningful names.

<figure><img src="https://github.com/lumelinc/PowerTableDocs/blob/main/.gitbook/assets/image%20(76).png" alt=""><figcaption><p>Rename unpivoted columns</p></figcaption></figure>


---

# 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.fabricplan.com/infobridge/9.-data-transformations/pivot-column.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.
