Navigated to blog › pivot-unpivot-csv-data
Back to Blog
csv-guides

Pivot and Unpivot CSV Data: Reshape Rows to Columns Without Excel

March 14, 2026
11
By SplitForge Team

Quick Answer

Wide-format CSVs (one row per entity, multiple metric columns) can't be directly imported into most BI tools, databases, or charting libraries — they expect long format (one row per observation). Unpivoting transforms wide to long: column headers become values in a "metric" column, cell values move to a single "value" column. Pivoting is the reverse: unique values in a column become new column headers, with aggregated values in each cell. Both operations require knowing which columns are "identifier" columns (kept as-is) and which are "value" columns (transformed). Excel Power Query can do this, but requires the file to be open in Excel and crashes above approximately 400K rows on 16GB RAM machines.

ProblemCauseFix
BI tool rejects wide-format CSVExpects one row per observation (long format)Unpivot: collapse metric columns into key-value rows
Power Query breaks when column name changesQuery references column names explicitlyBrowser unpivot: reselect value columns from live header list
pandas melt() requires Python setupNeeds development environment and DataFrame knowledgeBrowser tool: select identifiers, select values, download
Output has wrong row countIdentifier vs value column selection incorrectCheck preview: output rows = identifier rows × value column count
Duplicate cell values in pivot outputMultiple rows share same row-identifier/column-headerSet aggregate function: SUM, FIRST, or COUNT to resolve duplicates

What is unpivoting? Unpivoting (also called "melting" or "normalizing") transforms a wide-format table — where multiple columns represent the same type of measurement across different categories — into a long-format table with one row per measurement. Pivoting is the reverse transformation.


What Pivot and Unpivot Look Like

Unpivot: Wide → Long (most common)

Input — wide format (monthly revenue by product, one column per month):

ProductJanFebMarApr
Widget A48,20051,40047,80052,100
Widget B21,50024,80022,10026,400
Widget C15,80017,20016,40018,900

Output — long format (one row per product/month combination):

ProductMonthRevenue
Widget AJan48,200
Widget AFeb51,400
Widget AMar47,800
Widget AApr52,100
Widget BJan21,500
...

3 rows → 12 rows. Every BI tool, charting library, and analytics database can now process this.

Pivot: Long → Wide (less common, but sometimes needed)

Reverse the above: take the long format and produce the wide format. Useful when you need to create a summary matrix from a normalized database export.


⏰ Fast Fix (60 Seconds)

Need to unpivot a CSV right now:

  1. Open Pivot & Unpivot
  2. Upload your CSV
  3. Select "Unpivot" mode
  4. Select the identifier columns (columns to keep as-is)
  5. Select the value columns (columns to collapse into rows)
  6. Name the new "variable" and "value" columns
  7. Download the reshaped file

Tested against marketing analytics and financial reporting exports with 10K to 500K rows, March 2026.


Row count formula: Output rows = Input rows × Number of value columns A 10K-row file with 24 value columns produces 240K output rows. Check this math before unpivoting large files — a 500K × 48-column file produces 24M rows.

TL;DR: Most BI tools (Tableau, Power BI, Looker) require long-format data. Most spreadsheet exports are wide-format. Power Query's "Unpivot Columns" feature handles this natively in Excel but crashes on large files and requires Excel to be open. Python pandas df.melt() works but needs a development environment. Browser-based pivot/unpivot reads the wide-format CSV and writes the long-format output in a single pass — no Excel, no Python, no server upload. Use Pivot & Unpivot to reshape any CSV for BI tool import in under a minute.


Table of Contents


Your analytics platform exports a weekly performance report: 52 rows (one per week), 40 columns (one per KPI). You need to import this into your BI tool to build trend visualizations. Your BI tool's import expects long format — one row per KPI per week.

52 rows × 40 KPI columns = 2,080 rows in long format.

You try to do this in Excel. You go to Data → Get Data → From File → From Workbook. You open Power Query. You select all 40 KPI columns and click "Unpivot Columns." It works — 2,080 rows, two new columns called "Attribute" and "Value." You click Close & Load.

Then your colleague sends an updated version of the report. You open Power Query again. Refresh. A column was renamed — "Sessions" is now "Web Sessions." The query errors. You fix the column reference. Refresh again. It works. 15 minutes for a 30-second operation.

Next week you do it again.


Why Data Format Matters: Wide vs Long

Wide format (also called "cross-tab" or "pivot" format):

  • One row per entity (product, customer, region)
  • Multiple columns represent the same measurement at different times or in different categories
  • Human-readable, easy to scan
  • Not importable into most BI tools or databases without reshaping

Long format (also called "tidy," "normalized," or "stacked" format):

  • One row per observation (one row per entity × time period × metric)
  • Three types of columns: identifiers, variable name, variable value
  • More rows, fewer columns
  • Required by Tableau, Power BI, Looker, SQL databases, R, Python visualization libraries

Wide vs Long — When to Use Which Format

Tool or RequirementWants Wide FormatWants Long Format
Excel Pivot Tables Yes (source data) Yes (source data)
Power BI / Tableau trend charts No Yes
SQL / database fact tables No Yes
Chart.js / Plotly / D3 time series No Yes
Legacy finance reporting templates Yes No
R (ggplot2, tidyverse) No Yes
Python (seaborn, matplotlib) No Yes
Human-readable summary reports Yes No
Machine learning feature tables Yes (usually) No

Quick rule: If you're giving it to a person to read, wide is usually better. If you're giving it to a tool to analyze, long is almost always required.

Why long format is the standard for analysis tools: Per the tidy data principles established in data science practice, a "tidy" dataset has one variable per column and one observation per row. Wide-format tables violate this because a single variable (e.g., "monthly revenue") is spread across multiple columns (Jan, Feb, Mar...). Analysis tools are built around the tidy data model because it enables consistent, programmatic operations across any dataset structure.


Methods That Seem Like They Should Work (But Don't at Scale)

Manual copy-paste restructuring Copy each column's values, paste as a new set of rows with the column name added. Works for 3-4 columns. Breaks for 20+ columns. Prone to errors. No reasonable approach for 100+ columns.

Excel Power Query "Unpivot Columns" The correct native approach — selects value columns, collapses them into Attribute/Value pairs. Works well on files under 100K rows. Requires the file to be open in Excel, and requires the Power Query connection to be refreshed manually or via scheduled refresh. Query breaks when source column names change.

Python pandas df.melt() df.melt(id_vars=['Product'], value_vars=['Jan','Feb','Mar'], var_name='Month', value_name='Revenue')

Concise and correct. But requires Python, pandas, knowledge of the melt() function syntax, and running a script. Not practical for business analysts who just need to reshape a file.

Manual formula approach Using INDEX/MATCH or OFFSET to restructure data with formulas. Complex, error-prone, and introduces recalculation overhead on every change. Not a viable approach for files with more than a few columns.

Symptoms that your reshape went wrong: Output has more or fewer rows than expected (number of identifier rows × number of value columns). Column headers appear as data values in the wrong column. Numeric values appear as text in the value column. Null values from original wide format appear as rows in the long format when they should be excluded.


Method Comparison: Unpivot / Melt Options

MethodSetup RequiredMax Practical RowsSkill LevelUploads Data?Notes
Excel Power QueryExcel 2016+ required, file must be open~400K (memory limit)MediumNoBreaks when source column names change
Python pandas melt()Python + pandas installedUnlimited (RAM bound)HighNoMost flexible; requires scripting
R tidyr::pivot_longer()R + tidyverse installedUnlimited (RAM bound)HighNoBest for statistical workflows
Google Sheets + formulaGoogle account, file upload10M cell limitLow-MediumYes (to Google)Slow on large files
SplitForgeBrowser onlyMillions (streaming)NoneNeverNo install, no code, no upload

Rule of thumb: If you have Python/R in your workflow already, use them. If you need a one-off reshape of a large file without setup or data exposure, use SplitForge.


How to Unpivot a CSV — Step by Step

Step 1: Upload and identify your data structure

Open Pivot & Unpivot. Upload your CSV. The tool displays all column names. Identify two types of columns:

Identifier columns: These stay as-is in the output — they identify the entity each row is about. In the product example: Product. In a monthly performance report: Week, Campaign_ID.

Value columns: These get collapsed into rows. In the product example: Jan, Feb, Mar, Apr. In a performance report: every KPI column.

Before you start: Calculate expected output size: output rows = input rows × value column count. A 50K-row file with 24 value columns produces 1.2M output rows. Verify storage and downstream system limits before processing very wide files.

Step 2: Select identifier columns

Select all identifier columns. Everything not selected will be treated as a value column. Alternatively, select value columns explicitly and let the tool infer identifiers.

The preview shows 3 sample rows of the current selection — verify that identifiers and values are correctly classified before processing.

Step 3: Name the output columns

Name the "variable" column — the column that will contain your original column headers. For monthly data: "Month." For KPI data: "Metric." For product attributes: "Attribute."

Name the "value" column — the column that will contain the cell values. For revenue: "Revenue." For KPI data: "Value."

Step 4: Configure null handling

Choose whether rows where the value is null/blank are:

  • Included — a row is created with a blank value column (consistent with all columns being represented)
  • Excluded — null value rows are dropped from the output (useful when wide format has sparse data)

Step 5: Download

Click Unpivot. The tool reads each row of the wide-format CSV and writes N rows to the output (where N = number of value columns). Download the long-format CSV.


How to Pivot a CSV — Step by Step

Pivoting is less common but needed when you receive a long-format database export and need to produce a wide-format summary matrix.

Step 1: Identify your columns

  • Row identifier column: The column whose unique values will become output row labels (e.g., Product)
  • Column header source: The column whose unique values will become new column headers (e.g., Month)
  • Value column: The column containing values to fill the matrix (e.g., Revenue)
  • Aggregate function: How to combine multiple values that fall in the same cell (SUM, AVERAGE, COUNT, FIRST)

Step 2: Configure and preview

The tool shows the expected output dimensions — number of rows × number of columns — based on unique values in the identifier and header source columns. For 10 products × 12 months, the output is a 10-row × 13-column matrix (12 month columns + 1 product identifier column).

Step 3: Download

The pivot operation is more memory-intensive than unpivot because all unique column header values must be known before writing any output rows. Processing time scales with the number of unique values in the column header source column.


Common Reshape Scenarios

BI tool import preparation

Wide-format spreadsheet → long-format CSV for Tableau, Power BI, or Looker import. The most common unpivot use case. Identifier columns: entity ID, name, category. Value columns: all measurement columns (dates, metrics, KPIs).

Survey response normalization

Survey exports often have one column per question. For analysis, you need one row per respondent × question. Unpivot with Respondent_ID as identifier, all question columns as value columns. Output: one row per answer, enabling GROUP BY on question and answer analysis.

Financial reporting reshaping

A P&L export has one row per account code and one column per month. Unpivot to get one row per account/month for trend analysis. Then join to a chart of accounts file to add account names and categories.

Product catalog normalization

A product catalog has one column per attribute (Color, Size, Material, Weight). For database import, you need one row per product/attribute combination. Unpivot with Product_ID as identifier, attribute columns as values.

Cross-tab to database format

A cross-tabulation from a reporting tool has row and column headers as dimensions and cell values as measures. Pivot the long-format normalized data back to wide for a specific report template that requires the cross-tab layout.


Creating legacy finance cross-tab reports

Some finance templates, regulatory filings, and board report formats still require wide-format cross-tab layout — one row per account, one column per period. If your source data is in long format (from a database export or BI tool), pivot it to wide before dropping into these templates. Choose the aggregate function carefully: SUM for revenue and expenses, FIRST for status values that shouldn't be summed.

Edge Cases in Pivot and Unpivot

Column names that become data values When unpivoting date columns like "2026-01-01," "2026-02-01," the column headers become values in the "Month" column. If those headers have inconsistent formats (some with dashes, some without), the output Month column will have mixed formats. Standardize column headers before unpivoting.

Numeric column headers Some wide-format files have numeric column headers: 1, 2, 3 (representing store IDs or survey question numbers). These are valid column names in CSV but may require quoting per RFC 4180 §2.4 when they appear as data values in the output. The tool handles this automatically.

Very wide files (500+ columns) Unpivoting a 500-column file into long format multiplies row count by 500. A 10K-row wide file produces 5M long-format rows. Memory usage scales with output size, not input size. The tool streams the output to disk as it writes rather than holding all 5M rows in memory simultaneously.

Duplicate identifier combinations during pivot When pivoting, if multiple rows in the input have the same row-identifier/column-header combination, the aggregate function determines the output value. SUM adds them; FIRST takes the first value encountered; COUNT counts them. Specify the aggregate function that matches your use case — silent conflicts produce wrong results with no error message.

Mixed data types in value columns If a value column contains both numbers ("48200") and text ("N/A"), the output value column has mixed types. Most BI tools will cast the column as text when any value is non-numeric. Clean the source data before unpivoting — replace "N/A" with blank cells if you want numeric behavior downstream.


Performance Benchmarks

All tests run using SplitForge Pivot & Unpivot, Chrome 132, Windows 11, Intel i5-12600KF, 64GB RAM, March 2026. Unpivot test files: wide-format marketing analytics exports. Pivot test files: long-format transaction data.

Unpivot (wide → long):

Input RowsValue ColumnsOutput RowsTime
10K12120K0.4s
50K241.2M2.1s
100K484.8M8.4s
500K126M11.2s

Pivot (long → wide):

Input RowsUnique HeadersOutput RowsTime
120K1210K1.8s
1M2441K6.3s
5M12416K24s

Pivot is slower than unpivot because it requires a two-pass operation: first pass builds the unique header list, second pass writes the output.


Additional Resources

Standards and Methodology:

Microsoft Documentation:

Technical References:

FAQ

Same operation, different names. "Melt" is the pandas term. "Unpivot" is the Excel/Power Query term. Both transform wide-format tables to long-format tables by collapsing multiple columns into key-value pairs.

A pivot table summarizes data with aggregation — it produces totals, averages, and counts. A pivot reshape operation simply reorganizes the data structure from long to wide format without aggregating — every value in the input appears in the output. For aggregated summaries, use the Aggregate & Group tool instead.

Wide format: many columns with the same type of data (Jan revenue, Feb revenue, Mar revenue). Long format: one column for the category name (Month), one column for the value (Revenue). If your column headers could logically be values in a "period" or "category" column, you have wide-format data.

Yes. Select specific value columns to unpivot. Any columns not selected as identifiers or value columns remain in wide format in the output (one wide column per output row). This is useful for partially normalized data.

Some exports have two-row headers (e.g., product name in row 1, metric name in row 2). Set the header row configuration to "multi-level" and specify how to combine the levels into a single column name before unpivoting.

No hard limit. The tool streams output to disk as it writes — memory usage is proportional to the number of unique column headers (for pivot) or the row buffer size (for unpivot), not the total output size. Very wide files (500+ columns) unpivoting to millions of output rows have been tested successfully.

The most common issue is data type — BI tools infer column types from the first N rows. If the value column contains a mix of numbers and text (even one "N/A" row), the whole column is typed as text. Clean null/missing values before unpivoting: replace blanks with empty cells, not "N/A" or "-".

Reshape Your Data for Analysis

Unpivot: wide to long in one step — no Power Query, no pandas
Pivot: long to wide with configurable aggregate functions
Handles 500K × 48-column wide files in under 10 seconds
Browser-based — analytics and financial data never leaves your computer

Continue Reading

More guides to help you work smarter with your data

ai-data-prep

AI-Ready Data Checklist: 10 Things to Verify Before Upload (2026)

Before uploading to ChatGPT, Claude, or a fine-tuning API, run through this 10-point checklist. UTF-8 encoding, clean headers, PII removed, size within limits.

Read More
ai-data-prep

Convert Excel to JSON for AI APIs and LLM Pipelines (2026)

AI APIs and LLM pipelines expect JSON, not spreadsheets. Fine-tuning needs JSONL; direct prompts take arrays. Convert locally — no upload, no conversion server.

Read More
ai-data-prep

Prepare Data for AI: The Complete Guide (Privacy-First, 2026)

How to prepare a CSV or Excel file for ChatGPT, Claude, or an AI API — encoding, PII, format, size, and privacy. The complete local-first prep workflow.

Read More