How to Unpivot Data in Tableau

Cody Schneider••8 min read

Getting your data into the perfect shape for analysis can feel like half the battle. You might have a spreadsheet where every new month or category is a new column, which seems logical at first, but quickly becomes a headache in Tableau. This article will show you exactly how to solve this common problem by unpivoting your data - transforming those columns into rows for easier and more powerful analysis.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Why You Need to Unpivot Data in Tableau

Tableau works best with "tall" data rather than "wide" data. But what does that actually mean? Let's break it down with a simple example.

Imagine you have sales data for different products, formatted like this:

Example: Wide Data Format

This is what we call a wide format. Each month's sales figures are in their own separate column. While this is easy for a human to read in a spreadsheet, it’s not ideal for analytical tools like Tableau.

If you wanted to see the sales trend over time, you’d have to create calculations for each month, and you couldn't easily filter by a single "Month" dimension. This is where unpivoting comes in.

Unpivoting (which Tableau, a bit confusingly, simply calls "Pivoting") is the process of turning those multiple columns ("Jan Sales, Feb Sales, Mar Sales") into two new columns: one for the attribute (Month) and one for the value (Sales).

Example: Tall Data Format

This is the tall format Tableau loves. Every row is a single, distinct observation: a specific product, in a specific month, with a specific sales value.

With data in this shape, you can instantly put "Month" on the Columns shelf and "Sales" on the Rows shelf to create a line chart, filter for specific months, or create complex calculations with ease.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Method 1: Using Tableau's Built-in Pivot Feature

The simplest way to unpivot data is by using the native Pivot feature directly on the Data Source page in Tableau Desktop. This method works perfectly for file-based data sources like Microsoft Excel, CSV files, text files, and Google Sheets.

Step-by-Step Guide to Pivoting in Tableau

Let's walk through the process using our sales data example.

1. Connect to Your Data Source

First, open Tableau and connect to your data file. After connecting, Tableau will take you to the Data Source page, where you'll see a preview of your columns and rows, likely in the wide format.

2. Select the Columns to Unpivot

In the data preview grid, identify all the columns you want to transform from columns into rows. In our case, these are Jan Sales, Feb Sales, and Mar Sales.

To select multiple columns:

  • Click the first column header (Jan Sales).
  • Hold down the Shift key on your keyboard.
  • Click the last column header (Mar Sales) to select all columns in between.
  • Alternatively, you can hold down the Ctrl (or Cmd on Mac) key to select individual columns one by one if they are not next to each other.

3. Apply the Pivot

With your columns selected, right-click on any of the highlighted column headers. A context menu will appear. From this menu, select the Pivot option.

4. Review the Pivoted Data

Tableau will immediately reshape your data. The columns you selected (Jan Sales, Feb Sales, Mar Sales) have now been transformed into two new columns:

  • Pivot Field Names: Contains the original column headers (e.g., "Jan Sales", "Feb Sales").
  • Pivot Field Values: Contains the corresponding values from those original columns (e.g., "$1,500", "$1,750").

Your data grid should now look like the "tall" format we discussed earlier.

5. Rename the New Columns for Clarity

Leaving the default names "Pivot Field Names" and "Pivot Field Values" is a bad habit. They're not descriptive and will make building visualizations confusing. Always rename them to something meaningful.

  • Double-click the header "Pivot Field Names" and rename it to something like "Month" or "Sales Period".
  • Double-click the header "Pivot Field Values" and rename it to "Sales".

This simple step makes your data source far easier to understand when you move to the worksheet to start building.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Method 2: Unpivoting Data with Tableau Prep

Tableau's built-in pivot is great for simple cases, but what if your data is more complex, or if you're connected to a database that doesn't support the native pivot feature? This is where Tableau Prep Builder shines.

Why Use Tableau Prep?

Tableau Prep is a dedicated tool for cleaning, shaping, and combining data before it ever gets to Tableau Desktop. It’s a great choice for unpivoting when you need to:

  • Work with data from a source not supported by the native pivot (like many databases).
  • Perform more complex cleaning steps in addition to unpivoting.
  • Automate the process for a large number of columns using a wildcard union.

Unpivoting Steps in Tableau Prep

  1. Connect to Data: Open Tableau Prep and connect to your data source.
  2. Add a Pivot Step: After connecting, add a 'Pivot' step to your workflow.
  3. Configure the Pivot: In the Pivot settings pane, simply drag the columns you want to unpivot from the field list (on the left) into the 'Pivoted Fields' area. Tableau Prep will automatically create the new pivot columns.
  4. Rename and Clean: Just like in Desktop, you can easily rename the new columns. You can also perform additional cleanup, like trimming whitespace from the 'Month' names.
  5. Output the Data: Once you're done, you can output the cleaned, tall data into a file (like a .hyper or .csv) that you can then connect to from Tableau Desktop for lightning-fast analysis.

One of the strongest features here is the wildcard pivot. If you have columns named Jan-2022, Feb-2022, Mar-2022, etc., instead of selecting them manually, you can set a rule to pivot any column that starts with a year, for example. This makes your workflow robust even when new data (e.g., a new month) is added to your source file.

Method 3: For the Pros - Unpivoting with Custom SQL

If you're connecting to a SQL-based database (like PostgreSQL, SQL Server, MySQL, etc.) and prefer to get your hands dirty, you can unpivot your data directly with a Custom SQL query.

When Is Custom SQL the Right Choice?

This method is for users who are comfortable writing SQL. It’s extremely powerful and offers maximum flexibility right at the source, especially when the other methods aren't available for your connection type or you need to perform other transformations in the same step.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

The UNION ALL Approach

There is no standard UNPIVOT command in every dialect of SQL, but the most universally compatible way to achieve this is by using UNION ALL.

Here's how you'd transform our "wide" sales data into a "tall" format using a Custom SQL query in Tableau:

SELECT
  product_id,
  'Jan Sales' AS month,
  jan_sales AS sales
FROM
  your_table_name

UNION ALL

SELECT
  product_id,
  'Feb Sales' AS month,
  feb_sales AS sales
FROM
  your_table_name

UNION ALL

SELECT
  product_id,
  'Mar Sales' AS month,
  mar_sales AS sales
FROM
  your_table_name

This query works by creating three separate SELECT statements, one for each month. The UNION ALL operator then stacks the results of each query on top of one another, effectively turning your columns into rows. You would add this query via the 'Custom SQL' option when you first connect to your database in Tableau.

Tips for a Smooth Unpivoting Process

To avoid common frustrations, keep these best practices in mind:

  • Check Data Types Post-Pivot: After unpivoting, Tableau sometimes misinterprets the data type of the "Values" column, especially if there were nulls or mixed characters. Double-check that your new 'Sales' column is correctly set as a Number (Decimal) or Number (Whole), not a String.
  • Rename Fields Immediately: It’s worth saying again! Nothing is more confusing than a dashboard full of dimensions and measures called "Pivot Field Names." Rename your fields as soon as you pivot them.
  • Mind the Terminology: Remember, the industry term for this is typically "unpivot," but Tableau's feature is called "Pivot." They achieve the same goal: moving from a wide to a tall data structure.
  • Beware of New Data: If you use the manual pivot method in Tableau Desktop and a new column is added to your source file (e.g., Apr Sales), it will not be automatically included in your pivot. You'll need to go back to the Data Source page and manually add it. If this is a frequent issue, using Tableau Prep with a wildcard pivot is the better long-term solution.

Final Thoughts

Unpivoting data is a fundamental skill that transforms clunky, wide datasets into a clean, tall format that's ready for serious analysis in Tableau. Whether you use the simple built-in pivot feature, the more robust Tableau Prep, or the powerful Custom SQL method, mastering this technique will unlock deeper insights and make building your dashboards much faster and more flexible.

All of these data prep steps, while necessary, take you away from the actual goal: getting answers from your data. At Graphed, we felt this pain ourselves, which is why we built a tool to eliminate this friction entirely. Instead of reshaping data manually, you connect your sources and simply ask a question in plain English, like "Show me my monthly sales trend for the last year." We handle the data wrangling and visualization for you, turning hours of data prep into a 30-second conversation.

Related Articles