SmartQueryTools

Unpivot CSV Files Online

Reshape CSV files from wide to long format directly in your browser. Melt multiple columns into variable/value pairs — no upload required.

How to unpivot CSV files

  1. Drop your file. The first column is ticked as an ID column by default.
  2. Tick every column that identifies a row, such as an ID, a name or a region. ID columns are repeated on every output row.
  3. Leave the columns you want to melt unticked. Each unticked column becomes rows holding its column name and its value.
  4. Name the two new columns. They default to variable and value.
  5. Click Unpivot, check the long-format preview, and download the result.

Your file is processed locally in your browser and is never uploaded. The free limit is 50 MB per file; larger files work if your device has the memory for them.

Worked example

An HR team runs a two-question pulse survey. The export has one row per respondent and one column per question, but the dashboard tool wants one row per answer. One respondent skipped the second question.

Input (CSV)

respondent_id,team,q1_score,q2_score
1041,Support,4,5
1042,Sales,2,
1043,Support,5,4

Settings

  • ID columns (ticked): respondent_id, team
  • Value columns (unticked): q1_score, q2_score
  • Variable column name: question
  • Value column name: score

Result

respondent_idteamquestionscore
1041Supportq1_score4
1041Supportq2_score5
1042Salesq1_score2
1042Salesq2_scoreNULL
1043Supportq1_score5
1043Supportq2_score4

Each respondent now has one row per question, with the ID columns repeated. Respondent 1042 skipped question 2, and that row is kept with an empty score. So the result has 6 rows, 3 respondents times 2 questions. Filter out empty scores afterwards if you only want answered questions.

Working with CSV files

Wide CSV exports often come from spreadsheets, with one column per month or per question. Blank cells in those columns load as NULL and are kept as rows with an empty value, so the long file has exactly rows times value columns. A cell holding a single space is not blank. It is text, and one such cell makes the whole column VARCHAR. Then every value is written as text, numbers included. Run Trim Whitespace and load the trimmed file here to keep the values numeric.

The CSV headers become values in the variable column exactly as written, with their spaces and capitals. A header "Jan 2026" becomes the text Jan 2026 on every matching row. Rename the headers first if you want tidy values such as 2026-01. The output CSV is usually far longer than the input, which is expected: 500 rows with 24 month columns can produce up to 12,000 rows.

Frequently Asked Questions

Why are my unpivoted CSV numbers written as text?

One of the value columns was loaded as text, often because of a stray symbol, a note like "n/a", or a lone space. Numbers and text cannot share a column type, so every value is converted to text. Fix the stray values and unpivot again to keep numbers.

Can I treat the old CSV headers as dates after unpivoting?

Yes. They come out as text in the variable column. If the headers look like 2026-01-31, cast that column to DATE. For other forms, such as Jan 2026, use Parse Dates with a custom pattern.

Are empty values kept?

Yes. Each input row gives one output row for every value column, even when the value is empty (NULL). Filter the value column afterwards if you want only filled values.

Can I unpivot columns of different types?

Yes. Whole numbers and decimals combine into a number column, and dates and timestamps into timestamps. Any other mix, such as numbers and text, is converted to text so the run still works.

How do I go back from long to wide?

Use the Pivot tool. Put the variable column into the column headers and use the value column for the cells.

Related Tools