Switch Data in Columns to Rows
Transpose or Unpivot (Some) Fields
This will be another tutorial on transposing horizontal data into vertical data.
But this technique has a twist. No, wait! TWO twists!
Twist 1: we don’t want to change ALL the columns in our data; only certain columns.
Twist 2: we don’t want to lose the empty cells after the transposition; we want to see them as zeroes in the final version.
We will solve this problem using the “Get and Transform” tools located on Excel’s Data tab.
I’ve covered three other techniques for similar situations. They are:
- The TRANSPOSE function
- Copying and Pasting as transposed data
- The “R1C1” Trick
You can check out the links for those videos below.
Get and Transform
The “Get and Transform” tools have been widely available since Excel 2016. Prior to 2016, the tools were available via a free download as part of the Power Query toolset.
Our dataset contains sales for a year grouped by month (blue), and each row represents an App/Type grouping (yellow).
We want to transpose the monthly data and combine it with the App/Type data. Our result should have
- 12 rows for “WenCaL/Sales” (Jan…Dec)
- 12 rows for “WenCaL/Volume” (Jan…Dec)
- 12 rows for “WenCaL/Returns” (Jan…Dec), etc.
Problem with Blanks
One of the issues with traditional transpose strategies is wherever an empty cell exists, no row will be created for that App/Type combination.
To solve this issue, we will need to “zero fill” all the empty cells in the range of numbers.
Step 1 – Pull the Data into Power Query
The Power Query suite of tools (located in the “Get and Transform” group on the Data tab) will allow us to quickly and easily correct this data.
Click anywhere in the data (anywhere in A3:N12) and select Data (tab) -> Get & Transform Data (group) -> From Table/Range.
Provided there are no completely blank rows or columns in the data, the Create Table dialog box’s selection range should be correct. If not, make the necessary adjustments. Also, make sure the “My table has headers” option is selected then click OK.
The data will be sent to the Power Query Editor for further processing.
The Power Query Editor is an entire suite of tools used to fix virtually any data irregularity or data transformation issue.
The first thing we will do is to select the Name field from the Query Settings -> Properties panel on the right and change the name to something more meaningful, like “TableFinal”.
Step 2 – Fix the Data
Our first task will be to replace all the empty value cells with zeroes. Empty cells will be skipped in the next step when we transpose the table. Since we don’t want chronological gaps in our data, we need to occupy the empty cells with a value.
NOTE: In Power Query, an empty cell is labeled as a “null” cell. This is just a fancy way to say “empty” in Power Query.
We have 12 columns of monthly data to replace nulls with zeroes.
Click the header of the “Jan” column, scroll to the right, hold CTRL then click the header of the “Dec” column.
With the 12 month columns highlighted, select Home (tab) -> Transform (group) -> Replace Values.
In the Replace Values dialog box, type “null” (no quotation marks) in the Value To Find field, and a “0” (no quotation marks) in the Replace With field and click OK.
All the “null” cells have been replaced with zeroes.
Step 3 – Transposing the Months
The next step is to transpose the month columns and create associated entries for each corresponding App/Type combination.
We could select the month columns like we did earlier and then transpose them but imagine if instead of 12 month columns there were 1,000 product columns.
A faster method would be to select the two columns that we will be reproducing, the App and Type columns, and then instruct Power Query to fix all the OTHER columns, leaving our selected columns out of the process.
Select the App and Type columns, then select Transform (tab)-> Any Column (group) -> click the small arrow next to Unpivot Columns -> Unpivot Other Columns.
The data has been transposed.
Step 4 – Loading the Results into Excel
To load the results into Excel, select Home (tab) -> Close (group)-> Close & Load.
We have our transposed list in Excel as an official Excel Table.
We can now create Pivot Tables, Charts, filter, and sort to our heart’s delight.
Feel free to Download the Workbook HERE.
Excel ESSENTIALS for the REAL World (The Complete Excel Course)
From Excel Beginner to Professional
Learn Excel from Scratch
OR Improve Your Excel Skills to Become More Confident
Check out our best-selling course