How do I change column headers to a variables under a single column?

%3CLINGO-SUB%20id%3D%22lingo-sub-2665107%22%20slang%3D%22en-US%22%3EHow%20do%20I%20change%20column%20headers%20to%20a%20variables%20under%20a%20single%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2665107%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20all%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20dataset%20with%20the%20first%20column%20header%20of%20'SKU%20List'%20with%203000%20SKUs%20listed.%20The%20next%2010%20columns%20headers%20are%20sales%20from%202010%20to%202020%20and%20the%20contents%20in%20the%20cells%20are%20the%20number%20of%20units%20sold.%20Hence%2C%20right%20now%2C%20there%20are%20a%20total%20of%2011%20columns.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20would%20like%20to%20move%20the%202010%20to%202020%20columns%20to%20a%20single%20'Year'%20Column%20with%20the%20units%20sold%20in%20the%20next%20column%20(compressing%20my%20dataset%20contents%20to%203%20columns)%2C%20what%20is%20the%20best%20way%3F%20Doing%20this%20so%20I%20can%20add%20further%20variables%20in%20the%20future%20instead%20of%20using%20the%20year%20numbers%20as%20a%20column%20header.%20I%20do%20understand%20that%20it%20will%20make%20my%20Excel%20dataset%20a%20lot%20longer%20(as%20each%20SKU%20goes%20from%201%20row%20to%2010%20rows)%20but%20that's%20fine.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20help%20in%20advance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2665107%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2665152%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20change%20column%20headers%20to%20a%20variables%20under%20a%20single%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2665152%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1132306%22%20target%3D%22_blank%22%3E%40pheerful%3C%2FA%3E%26nbsp%3BConnect%20to%20the%20entire%20table%20with%20PowerQuery.%20Select%20the%20first%20column.%20Right-click%20and%20select%20Unpivot%20other%20columns.%20Close%20and%20load%20back%20to%20a%20table.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2665938%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20change%20column%20headers%20to%20a%20variables%20under%20a%20single%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2665938%22%20slang%3D%22en-US%22%3EThank%20you%20for%20the%20response.%20I%20cannot%20install%20PowerQuery%20as%20it%20is%20a%20company%20laptop%20and%20they%20are%20very%20strict%20about%20what%20we%20do.%20Is%20there%20an%20alternative%20solution%20other%20than%20manually%20inserting%2Ftransposing%3F%20We%20do%20have%20access%20to%20macros.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2666006%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20change%20column%20headers%20to%20a%20variables%20under%20a%20single%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2666006%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1132306%22%20target%3D%22_blank%22%3E%40pheerful%3C%2FA%3E%26nbsp%3BFrom%20Excel%202016%2C%20PQ%20is%20integrated%20in%20Excel.%20So%20you%20are%20on%20an%20older%20version%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2666123%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20change%20column%20headers%20to%20a%20variables%20under%20a%20single%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2666123%22%20slang%3D%22en-US%22%3EI%20am%20using%20Excel%20on%20Mac%20and%20I%20don't%20think%20PowerQuery%20is%20supported%20natively%20yet%20on%20my%20version%20at%20least.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2666194%22%20slang%3D%22en-US%22%3ERe%3A%20How%20do%20I%20change%20column%20headers%20to%20a%20variables%20under%20a%20single%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2666194%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1132306%22%20target%3D%22_blank%22%3E%40pheerful%3C%2FA%3E%26nbsp%3BOkay%2C%20then%20you%20may%20forget%20it!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi all,

 

I have a dataset with the first column header of 'SKU List' with 3000 SKUs listed. The next 10 columns headers are sales from 2010 to 2020 and the contents in the cells are the number of units sold. Hence, right now, there are a total of 11 columns.

 

If I would like to move the 2010 to 2020 columns to a single 'Year' Column with the units sold in the next column (compressing my dataset contents to 3 columns), what is the best way? Doing this so I can add further variables in the future instead of using the year numbers as a column header. I do understand that it will make my Excel dataset a lot longer (as each SKU goes from 1 row to 10 rows) but that's fine.

 

Thanks for your help in advance.

6 Replies

@pheerful Connect to the entire table with PowerQuery. Select the first column. Right-click and select Unpivot other columns. Close and load back to a table.

Thank you for the response. I cannot install PowerQuery as it is a company laptop and they are very strict about what we do. Is there an alternative solution other than manually inserting/transposing? We do have access to macros.

@pheerful From Excel 2016, PQ is integrated in Excel. So you are on an older version?

I am using Excel on Mac and I don't think PowerQuery is supported natively yet on my version at least.

@pheerful Okay, then you may forget it!

 

@pheerful 

If from left (Source) to right (Target)

image.png

- create Target table with headers and only one empty row. Add formulas to it

Year:
=INDEX(Source[SKU], MOD(ROW()-ROW(Target[[#Headers],[SKU]])-1,ROWS(Source))+1)

SKU:
=INDEX(Source[#Headers],1,INT((ROW()-ROW(Target[[#Headers],[SKU]])-1)/ ROWS(Source)  )+2)

Qty:
=INDEX(Source, MATCH([@SKU],Source[SKU],0), MATCH([@Year],Source[#Headers],0))

-starting from this first row select the range where to expand, e.g. type in name box P5:R40000 if P5 is the reference on left top cell with data in Target table

- Ctrl+D

- Target table will be expanded on entire range.

 

I did that on Windows, on Mac it shall be similar.