Skip to content
Learn › Clean and shape data › Group and pivot: open the docs menu

Turn columns into rows with Unpivot

Unpivot turns a wide table into a long one: column headers become row values. Use it when you have one column per period or category, such as Jan_Sales, Feb_Sales and Mar_Sales, and need one Month column and one Sales column. Most grouping, joining and analysis works best on the long layout.

Unpivot panel with Dimensions and Name columns selected, label column title Product, value column title Size, and an example

Unpivot columns into rows

  1. In your View, click Describe your transformation, then Reshape, Group & Pivot › Unpivot.
  2. In Select columns to be transposed, pick the columns to turn into rows. Once you pick one, only columns of the same type are offered.
  3. In "Label" column title, name the new column that will hold the old column headers.
  4. In "Value" column title, name the new column that will hold the old cell values.
  5. If the columns are numbers or dates, set Format. For numbers, set the number format of the value column. For dates, click Choose date format and pick one.
  6. Click Apply.

All other columns are kept and repeated on each new row. The two new names must differ from each other and from existing columns.

Example: a View has store, Jan_Sales, Feb_Sales and Mar_Sales. Select the three sales columns, name the label column Month and the value column Sales, and click Apply. Each store now has three rows, one per month.

Troubleshooting Unpivot

SymptomCauseFix
"A column with same name already exists. Try another value" (Unpivot)A new column name is already usedChoose a different label or value column title
"The new value column does not carry over the meaning of the columns you stack (an ID, a currency or a percentage). It starts as a plain column." (Unpivot)The stacked columns were marked as an ID, currency or percentageAdd a Convert Column Type step after the Unpivot to restore the meaning
Was this page helpful?

Something wrong? support@mammoth.io