Pivoting Data
Wide ↔ Long
Learn how to reshape your data on the Tableau Data Source page: convert wide-format tables into long-format tables and back again.
What Is Pivoting?
Pivoting is the act of reshaping a table so that column headers become row values or vice-versa. In Tableau, you pivot directly on the Data Source page without writing any code.
Why Does Format Matter?
Tableau works best with long (tidy) data. When your data is wide, you cannot easily drag a single field onto Color or Rows to compare categories. Pivoting solves this instantly.
The Visual Transformation
The Pivot Rule
When you select columns and pivot them in Tableau, two new fields are created:
Wide vs. Long: Key Differences
| Wide Format | Long Format | |
|---|---|---|
| Structure | One column per measure | One row per observation |
| Columns | Many (grows with categories) | Few (fixed structure) |
| Rows | Fewer | More (grows with categories) |
| Tableau Friendly? | Often needs pivoting | Ready to use |
| Use Case | Spreadsheet summaries | Visualization, analysis |
Recognizing Wide Data
Before you pivot, you need to spot the problem. Here are the telltale signs:
How to Pivot in Tableau
Example 1: Monthly Sales
A spreadsheet tracks revenue per store per month. The columns are Store, Jan, Feb, Mar.
Example 2: Survey Scores
A survey file has columns: Student, Math Score, Science Score, English Score. You want to compare scores by subject on a single bar chart.
Example 3: Multi-Year Census
A government dataset has columns: County, State, Pop_2010, Pop_2015, Pop_2020. You want a line chart of population over time.
When Not to Pivot
Not every multi-column dataset needs pivoting. Here are cases where your data is already structured correctly:
Undoing a Pivot
If you pivot the wrong columns or change your mind, you can reverse the operation easily.
The Row Count Formula
Understanding how many rows you will get after pivoting helps you verify the result is correct.
Common Mistakes
Summary: Pivoting at a Glance
| Concept | Details |
|---|---|
| What it does | Converts column headers into row values |
| Where to do it | Data Source page (not a worksheet) |
| Creates | Pivot Field Names + Pivot Field Values |
| Row formula | \( R_{\text{original}} \times C_{\text{pivoted}} \) |
| Undo method | Dropdown arrow on field header → Remove Pivot |
| When to use | Repeated measure names across column headers |
| When NOT to use | Columns are different measures or data is already long |
Question 1 of 5
A dataset has 5 product rows and columns: Product, Jan, Feb, Mar, Apr. If you pivot Jan through Apr, how many rows will the pivoted table have?
Question 2 of 5
After pivoting, the original column headers end up in which generated field?
Question 3 of 5
A table has columns: Employee, Department, Salary, Bonus. You want to compare Salary and Bonus. Should you pivot?
Question 4 of 5
Where in Tableau do you perform a pivot operation?
Question 5 of 5
You accidentally pivoted the wrong columns. What is the correct way to undo it?