# 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.&#x20;

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2F9x2hMu4lHNYEnrdX2BMR%2Fimage.png?alt=media&#x26;token=cc7bcc0a-2e0f-462a-8800-29e1a1b3612a" 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://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FT7Z7btc7fyvTUrEW2heA%2Fimage.png?alt=media&#x26;token=4a97f45f-0455-46e9-aa5a-8cc9bffbf165" 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://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FXIbHlyV7n1K5lIIYvvGI%2Fimage.png?alt=media&#x26;token=24c85e67-f83f-40a6-9b80-5dfb2688bef9" 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://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2Fy8bAaMqbjilgvJ83Uia0%2Fimage.png?alt=media&#x26;token=5965f45a-1065-4c99-9d0d-3059851fe181" alt=""><figcaption><p>Pivot column configuration</p></figcaption></figure>

Notice how each product is now a separate column.

<figure><img src="https://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FwYlt1w5RcGgVxO8ADqji%2Fimage.png?alt=media&#x26;token=cb1150ba-42d1-4267-8177-67cb35d6ab58" 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://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2F2mBuUURXHiENaaY1RV7a%2Fimage.png?alt=media&#x26;token=5177754c-cea2-4105-90c5-0e9e6ee7bf96" 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://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FlDfTlEyloIrs9GwNJOq8%2Fimage.png?alt=media&#x26;token=431cc174-91c9-4347-a4c6-6c5a738782da" 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://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FeieSEVrsLROrNFkGd1FE%2Fimage.png?alt=media&#x26;token=016577a7-1205-4919-94d1-be392af09c13" 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://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FktjnnRv2ZZq8d9WfXvWY%2Fimage.png?alt=media&#x26;token=edf0aeba-960c-4954-8dfc-ea37cb489e5e" 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://3062809325-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEbkCXCUXmtUq5tcnUtZE%2Fuploads%2FGQ0sH1rcKsXNlQ7gs6e2%2Fimage.png?alt=media&#x26;token=341559f0-fa23-4c5d-b8f7-412b00e9ec0e" alt=""><figcaption><p>Rename unpivoted columns</p></figcaption></figure>
