Transform multi-level table format, maybe with pivot table?

montaguelord

New Member
Joined
Dec 4, 2008
Messages
5
I have an Excel 2016 file with a large set of panel data in the following actual form:
VARISOVALUE
199019911992
IMPORTS ARG 1,287 NA NA
IMPORTS AUS 9,178 447 10,792
IMPORTS AUT NA NA 1,325
GDP ARG 153 206 248
GDP AUS 323 324 317
GDP AUT 167 174 196

<tbody>
</tbody>
I need to transform it to the following desired form:
ISOYEARVAR
IMPORTSGDP
ARG19901,287 153
ARG 1991 NA 206
ARG1992 NA 248
AUS19909,178 323
AUS1991 447 324
AUS199210,792 317
AUT1990 NA 167
AUT1991 NA 174
AUT19921,325 196

<tbody>
</tbody>
Can anyone suggest a way to automatically transform the data from the actual format to the desired form:
I thought that a pivot table might work. But I don’t know how to do a multi-level pivot table that would have the ISO and YEAR in the same line.
Any suggestions would be grately appreciated!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hello and welcome to the board. I will assume you know pivot tables, if you are not sure of how to do something let me know. There may be other ways, but if you have Power Query, I would unpivot the data, then the rest is simple. to unpivot see this Mrexcel video:

https://www.youtube.com/watch?v=yX-QNxaOj9c

Note mrexel says go to the Power Query tab, depending on your version that is now on the Data ribbon under Get and Transform

After you unpivot the rest is a simple pivot table. Note though that the NAs will show as zeros, but you can change that to show NA, assuming you have no actual zeros in your data.
 
Last edited:
Upvote 0
Great! Fantastic! Almost there.... I followed the video instructions and end up with the table below. There are 3 changes that I need to complete the transformation:
(1) most importantly, I need the ISO (country) label lined up with the Years (ARG 1990; ARG 1991;....AUT 1992)
(2) remove the last column (Grand Total)
(3) remove the rows showing the Grand Total for each ISO.
My 'Desired Table' above shows it better.
Here is what I get after the 'unpivot table with Power Query' and Pivot Table transformation:
Sum of ValueColumn Labels
Row LabelsGDPIMPORTSGrand Total
ARG
1990153.20512871440.205
1991205.5150205.515
1992247.9870247.987
ARG Total606.70712871893.707
AUS
1990323.2191789501.21
1991323.72354475770.723
1992317.4791079211109.479
AUS Total964.4122541726381.412
AUT
1990166.8670166.867
1991174.4350174.435
1992195.50613251520.506
AUT Total536.80813251861.808
Grand Total2107.9272802930136.927

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Great, so when you are clicked in your PT, go to the Design contextual ribbon, all the way to the left, find Report Layout, select show in Tabular, and also select Repeat allitem labels, Go to Subtotals and selectdo not show subtotal, and Grand Total, do not show Grand Totals, that shouldshow what you want.
 
Last edited:
Upvote 0
Excellent! Solved. Thank you both for your quick replies and for the clear instructions.
One final query, since my data set is so large and I'm trying to reduce the work:
Below is the result of your instructions, which is fine. But would it be possible to somehow get the ISO names to repeat for each year, rather than for just the first year. Not a problem, since I can always copy down. But if there's a way to automate the process, that would be great.

Sum of ValueVAR
ISOYearGDPIMPORTS
ARG1990153.2051287
1991205.5150
1992247.9870
AUS1990323.219178
1991323.7235447
1992317.47910792
AUT1990166.8670
1991174.4350
1992195.5061325

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
Sure, I think you missed this one step: under Report Layout... also select "Repeat All Item Labels"
 
Upvote 0
Excellent, that worked. I guess it didn't work the first time because I clicked on Repeat all item labels right after I selected show in Tabular. It appears that those two steps need to be done separately.
Many thanks for your extremely helpful and timely support!
 
Upvote 0

Forum statistics

Threads
1,214,422
Messages
6,119,395
Members
448,891
Latest member
tpierce

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top