<!-- https://learnsql.cpetoday.com/functions/m/table-unpivotothercolumns -->
# Table.UnpivotOtherColumns

Language: Power Query M
Category: Table: headers and shape
Syntax: Table.UnpivotOtherColumns(table as table, pivotColumns as list, attributeColumn as text, valueColumn as text) as table
Summary: Turns every column except the ones you keep into rows.
Returns: A long table, with the kept columns repeated for each column that was turned into rows.
Level: Intermediate
Related: Table.Unpivot, Table.Pivot, Table.SelectColumns, Table.TransformColumnTypes

## What it does
Table.UnpivotOtherColumns turns every column into rows, except the columns you keep. This is the safer form of Table.Unpivot for a monthly grid, because a new month column is picked up automatically. You name the identifying columns, such as the account and the department, and the rest become rows.

## Syntax and arguments
- **table**: the wide table to change. Required.
- **pivotColumns**: the list of columns to keep as identifiers, in braces. Despite the name in the signature, these are the columns that stay as they are, not the ones that become rows. Required.
- **attributeColumn**: the name of the new column that holds the old headings, in quotes. Required.
- **valueColumn**: the name of the new column that holds the values, in quotes. Required.

## Example
A budget grid has Account and Department as its identifying columns, and a month column for each month. Every month column becomes a row without naming the months.

```powerquery
let
    Source = Excel.CurrentWorkbook(){[Name = "BudgetByDept"]}[Content],
    Long = Table.UnpivotOtherColumns(Source, {"Account", "Department"}, "Month", "Budget")
in
    Long
```

Each row is one account, one department and one month. When a month column is added to the sheet next year, it is turned into rows as well, with no change to the query.

## Things to watch
- Every column that is not kept is turned into rows. A notes or total column you forgot to keep is unpivoted too, so list the keys carefully.
- The values come out as text if the source has mixed types. Type the Budget column after the step.
- A total column in the grid is also unpivoted. Remove it first.
- Query folding: this step usually breaks folding, so place it after the filters.

## In business terms
Planning files tend to gain a column each year. Keeping the identifying fields and unpivoting the rest means the same query works for the next budget cycle without edits.
