pbPassingBI
/
Blending & structuring intermediate 6 min

Cross Tab and Transpose

Pivoting rows to columns and back.

What you'll be able to do
  • Pivot with Cross Tab
  • Unpivot with Transpose
  • Know which shape each downstream step needs

Transpose — wide to long

wide product | Jan | Feb A 100 120 B 90 140 melt pivot long product | month | value A Jan 100 A Feb 120 B Jan 90 charts and groupby want long data
Most reshaping work is moving between these two forms.

Cross Tab — long to wide

Cross Tab does the reverse. You set:

  • Group data by — what stays as rows
  • New column headers — the field whose values become columns
  • Values for new columns — what fills the cells
  • Method for aggregating — sum, count, first, concatenate

It aggregates by necessity, since several rows can land in one cell.

Cross Tab renames fields

Column headers are built from your data, so they inherit whatever is in it — spaces become underscores, and a value starting with a digit gets prefixed. Downstream tools referencing those names then break when the data changes.

The order problem

Cross Tab sorts new columns alphabetically. Month names come out April, August, December — not calendar order.

The usual fix is to prefix with a number (01 Jan) before the Cross Tab, then strip it afterwards if needed.

When to use which

Transpose before analysis; Cross Tab at the end for presentation. A workflow that transposes, aggregates, then cross-tabs into a report layout is a very common and very readable shape.

Key points
  • Transpose unpivots wide to long; Cross Tab pivots long to wide
  • Cross Tab builds column names from data — they change when the data does
  • Cross Tab sorts columns alphabetically, not chronologically
Check yourself