# Excel question: transform data table from landscape to portrait

**URL:** <https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311>\
**Category:** Factual Questions\
**Created:** [August 6, 2024, 3:39am UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311 "2024-08-06T03:39:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![penultima\_thule](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/penultima_thule/32/3833_2.png) [@penultima\_thule](https://boards.straightdope.com/u/penultima_thule)\
**Post date:** [August 6, 2024, 3:39am UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/1 "2024-08-06T03:39:18Z")

</div>

I have a listing of a couple of thousand skus and their national total inventory quantity by month.  
For budgetary purposes I need to partition the national totals into four warehouses.

I know the BP proportion by whse by sku.  
I can simply calculate the individual whse quantities using a formula into four separate columns  
(the final table needs to include time parameters eg sku_whse_month\*week qty)

But I need to transform the table essentially from landscape with one row for each sku and four whses and 12 months per row into a portrait table where there are rows per sku per month per week each with one whse value

so: (ignoring the time parameter)  
From:  
SKU1 National 100  
To:  
SKU1 WhseAA 15  
SKU1 WhseBB 45  
SKU1 WhseCC 25  
SKU1 WhseDD 15

I have a couple of techniques I use to do this transformation depending on the scale but methinks they are just clunky either with c&p or with pivot tables. There must be a SDMB Excel user who has a nifty technique to perform the task more efficiently and elegantly.

---

<div class="post-metadata">

**Author:** ![Stranger\_On\_A\_Train](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Stranger\_On\_A\_Train](https://boards.straightdope.com/u/Stranger_On_A_Train)\
**Post date:** [August 6, 2024, 3:51am UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/2 "2024-08-06T03:51:37Z")

</div>

> [@penultima\_thule](#):
>
> But I need to transform the table essentially from landscape with one row for each sku and four whses and 12 months per row into a portrait table where there are rows per sku per month per week each with one whse value
> 
> so: (ignoring the time parameter)  
> From:  
> SKU1 National 100  
> To:  
> SKU1 WhseAA 15  
> SKU1 WhseBB 45  
> SKU1 WhseCC 25  
> SKU1 WhseDD 15
> 
> I have a couple of techniques I use to do this transformation depending on the scale but methinks they are just clunky either with c&p or with pivot tables. There must be a SDMB Excel user who has a nifty technique to perform the task more efficiently and elegantly.

I’m having some difficulty in parsing exactly what it is you are trying to do, but if I understand it, a pivot table is the “nifty technique to perform the task more efficiently and elegantly” that you are looking for. Although they look intimidating a first (and the way Excel implements the structure of pivot tables is not a model of clarity), they are actually quite powerful in doing these kind of transformations and slicing/filtering/organizing data. Any other way of doing this is going to be a kludge of creating a bunch of cell functions and sorts that will likely break the first time you make any change.

Stranger

---

<div class="post-metadata">

**Author:** ![penultima\_thule](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/penultima_thule/32/3833_2.png) [@penultima\_thule](https://boards.straightdope.com/u/penultima_thule)\
**Post date:** [August 6, 2024, 4:01am UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/3 "2024-08-06T04:01:57Z")

</div>

Yes, I use pivot tables constantly.  
The transformation here is going to be from one row per sku with (4 whses \* 52 weeks) columns into 208 rows per sku.  
If I’m going to drag and drop that many columns then the chances of getting some in the wrong sequence is rather high.

---

<div class="post-metadata">

**Author:** ![OldGuy](https://avatars.discourse-cdn.com/v4/letter/o/3bc359/32.png) [@OldGuy](https://boards.straightdope.com/u/OldGuy)\
**Post date:** [August 6, 2024, 4:14am UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/4 "2024-08-06T04:14:44Z")

</div>

I’m not sure what you want to do, but does Excel’s transpose command do it?

> **[Transpose (rotate) data from rows to columns or vice versa - Microsoft Support](https://support.microsoft.com/en-us/office/transpose-rotate-data-from-rows-to-columns-or-vice-versa-3419f2e3-beab-4318-aae5-d0f862209744)**
>
> How to use Transpose in Excel to rotate columns and rows to rearrange your worksheet data.

---

<div class="post-metadata">

**Author:** ![penultima\_thule](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/penultima_thule/32/3833_2.png) [@penultima\_thule](https://boards.straightdope.com/u/penultima_thule)\
**Post date:** [August 6, 2024, 4:25am UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/5 "2024-08-06T04:25:45Z")

</div>

No, alas. 😢

Doing that will produce a table with 208 rows and over 2,000 columns with the row parameters now showing as column titles.

---

<div class="post-metadata">

**Author:** ![md-2000](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@md-2000](https://boards.straightdope.com/u/md-2000)\
**Post date:** [August 6, 2024, 5:04am UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/6 "2024-08-06T05:04:46Z")

</div>

I find this -

> You can **use the ADDRESS function** to obtain the address of a cell in a worksheet, given specified row and column numbers. For example, ADDRESS(2,3) returns $C$2. As another example, ADDRESS(77,300) returns $KN$77.

So you can expand and get 4 rows per SKU by using mod(4) of the row number; not an expert in Excel by any means, but…  
So to get SKU in sets of 4, have a second tab that references the first tab sheet?  
A … B Col A is a simple counter, hide it when done. Col B contains value of other sheet col 1.

1 =Sheet1;address(MOD(A1+3,4),1 ) - which should return mod (4,4)=1 the contents of $A$1 in the first sheet.(The SKU I assume?)  
2 =Sheet1;address(MOD(A2+3,4),1) ditto mod (5,4)=1  
3 =Sheet1;address(MOD(A3+3,4),1) ditto mod (6,4)=1  
4 =Sheet1;address(MOD(A4+3,4),1) ditto mod (7,4)=1  
5 =Sheet1;address(MOD(A1+3,4),1) -which will now give you mod(8,4) =2 so $A$2, the second SKU  
6  
7  
8  
9  
…etc.

I assume if you do the content once and copy cells down, it will increment like most excel formulas?  
If you need a row per week _and_ warehouse, then it’s mod 208?

Just a thought.  
But, you’ll get a ton of formula, big sheet.  
Once you have what you need, “paste values” to another sheet where it won’t spend forever recalculating every time you touch something…

---

<div class="post-metadata">

**Author:** ![Stranger\_On\_A\_Train](https://avatars.discourse-cdn.com/v4/letter/s/13edae/32.png) [@Stranger\_On\_A\_Train](https://boards.straightdope.com/u/Stranger_On_A_Train)\
**Post date:** [August 6, 2024, 5:07am UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/7 "2024-08-06T05:07:49Z")

</div>

> [@penultima\_thule](#):
>
> The transformation here is going to be from one row per sku with (4 whses \* 52 weeks) columns into 208 rows per sku.

So each row is one SKU followed by a series of quantities divided into the warehouses, repeated ‘horizontally’ (in the row) for each weak of the year, and you are trying to arrange each into individual rows organized by month, then subdivided by week within the month, and then further subdivided by each warehouse?

If this is the case, I think what you are trying to do is beyond simple functionality in Excel. You’re either going to have to write some VBA routines to automate reorganizing the data, or take it into another tool. I would personally use Python and Pandas to do this because of how easy it is to vectorize data handling functions in Python, and there are probably some clever ways you can use to do all of this within Pandas dataframe operations, but of course you’d have to be comfortable using Python and Pandas or spend the time to get up to speed.

Stranger

---

<div class="post-metadata">

**Author:** ![penultima\_thule](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/penultima_thule/32/3833_2.png) [@penultima\_thule](https://boards.straightdope.com/u/penultima_thule)\
**Post date:** [August 6, 2024, 5:26am UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/8 "2024-08-06T05:26:37Z")

</div>

> [@md-2000](#):
>
> Just a thought.

Now that has distinct possibilities. Excellent. Thank you.

My current approach is to use multiple pivot tables to progressively swing the columns into rows.

After 3 transformations I get a data table with over 250k rows and a handful of columns. Just as Power BI likes it.

Hence my appeal to wiser and/or more laterally thinking minds. 🙂

---

<div class="post-metadata">

**Author:** ![Typo\_Knig](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Typo\_Knig](https://boards.straightdope.com/u/Typo_Knig)\
**Post date:** [August 6, 2024, 4:28pm UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/9 "2024-08-06T16:28:10Z")

</div>

My favorite Excel trick is using the ADDRESS() function with internal formulas to figure out a cell reference, and the INDIRECT() function to get the value for that cell reference. Building on md-2000’s example

Cell for transformation would have indirect(address(mod(a2+3,4),1,1,1)) etc. Some guidance for indirect() [https://exceljet.net/functions/indirect-function](https://exceljet.net/functions/indirect-function)

---

<div class="post-metadata">

**Author:** ![md-2000](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@md-2000](https://boards.straightdope.com/u/md-2000)\
**Post date:** [August 6, 2024, 6:37pm UTC](https://boards.straightdope.com/t/excel-question-transform-data-table-from-landscape-to-portrait/1005311/10 "2024-08-06T18:37:34Z")

</div>

Oops, in my example, 5th row should be:

5 =Sheet1;address(MOD(A **5** +3,4),1)

If the sheet ends up being too big, you can do it incrementally.  
Create the first two columns only, SKU and warehouse.  
Paste values that, then used VLOOKUP to find the numbers from the SKU in col A to calculate per warehouse quantities, etc.  
Alternatively, create a sheet for each week, once you have the SKU’s in columns.  
Then copy and paste each sheet together into one, one below the other, sort by SKU.

Seriously, this is the sort of thing that begs for a database solution like Access or (good old days) dBase.
