+ Reply to Thread
Results 1 to 6 of 6

How do I flatten columns into rows?

  1. #1
    Registered User
    Join Date
    01-18-2019
    Location
    Morristown, NJ
    MS-Off Ver
    Version 1812 (Build 11126.20266 Click-to-Run)
    Posts
    4

    How do I flatten columns into rows?

    Newbie question (I'm not sure whether or not this is a pivot problem): How do I flatten columns B through ...n, such that the heading in row 1 of each of those columns become the column B value and the values in row 2 through ...n of each column are moved to column C, with each successive column's values moved underneath the previous column's values?

    Currently, column A row values are a list of categories and row 1 headers are location names, with each cell beginning with B2 being a percentage value.

    I've created a simple example below, where a table with 4x2 values becomes a table with 3x6 values, but assume a real table would have 44 categories and 12 locations, so a table with 13x44 values becomes a table with 3x528 values.

    Is this do-able with formulas? Any assistance is appreciated.

    Current State:

    Category Warehouse 1 Warehouse 2 Warehouse 3
    Widgets 30% 60% 18%
    Stuff 70% 40% 82%

    Desired State:

    Category Location Percentage
    Widgets Warehouse 1 30%
    Stuff Warehouse 1 70%
    Widgets Warehouse 2 60%
    Stuff Warehouse 2 40%
    Widgets Warehouse 3 18%
    Stuff Warehouse 3 82%
    Last edited by edtguy; 01-18-2019 at 09:57 PM. Reason: Marked as solved

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    24,733

    Re: How do I flatten columns into rows?

    Welcome to the forum.

    It would help if you attached a sample Excel workbook, then we could give you a solution which is geared exactly to your file.

    To do this, click on Go Advanced (below the Edit Window) while you are composing a reply, then scroll down to and click on Manage Attachments and the Upload window will open. Click on Browse and navigate to (and double-click) the file icon that you want to attach, then click on Upload and then on Close this Window to return to the Edit window. When you have finished composing your post, click on Submit Post. Do NOT try to use the Paperclip icon, as this does not work on this forum.

    Hope this helps.

    Pete

  3. #3
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: How do I flatten columns into rows?

    in Sheet2!A2
    =INDEX(Sheet1!A$2:A$3,NOT(MOD((ROW()-1),2))+1,1)

    in Sheet2!B2
    =INDEX(B$1:D$1,1,MOD(ROW()-2,3)+1)

    in Sheet2!C2
    =INDEX(B$2:D$3,QUOTIENT(ROW()-2,3)+1,MOD(ROW()-2,3)+1)

    copy down the columns

    Change the numbers in red to adjust row and column size of the table
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  4. #4
    Registered User
    Join Date
    01-18-2019
    Location
    Morristown, NJ
    MS-Off Ver
    Version 1812 (Build 11126.20266 Click-to-Run)
    Posts
    4

    Re: How do I flatten columns into rows?

    Thanks Pete. I'll remember that for next time, as Special-K has resolved my issue for me on this one.

  5. #5
    Registered User
    Join Date
    01-18-2019
    Location
    Morristown, NJ
    MS-Off Ver
    Version 1812 (Build 11126.20266 Click-to-Run)
    Posts
    4

    Re: How do I flatten columns into rows?

    Quote Originally Posted by Special-K View Post
    in Sheet2!A2
    =INDEX(Sheet1!A$2:A$3,NOT(MOD((ROW()-1),2))+1,1)

    in Sheet2!B2
    =INDEX(B$1:D$1,1,MOD(ROW()-2,3)+1)

    in Sheet2!C2
    =INDEX(B$2:D$3,QUOTIENT(ROW()-2,3)+1,MOD(ROW()-2,3)+1)

    copy down the columns

    Change the numbers in red to adjust row and column size of the table
    Thanks! With a little fiddling, I was able to get to the desired state. Here are the modified formulas:

    in Sheet2!A2
    =INDEX({source sheet}!$A$2:$A${last row},IF(MOD((ROW()-1),{data rows})=0,{data rows},MOD((ROW()-1),{data rows})),1)

    in Sheet2!B2
    =INDEX({source sheet}!$B$1:${last column}!$1,1,MOD(ROW()-2,{data columns})+1)

    in Sheet2!C2
    =INDEX({source sheet}!$B$2:${last column}!${last row}!,MOD(ROW()-2,{data rows})+1,QUOTIENT(ROW()-2,{data rows})+1)

    No doubt these formulas can be refined further, and use replaceable parameters, but it works for me meeting a deadline. Thanks again!

  6. #6
    Registered User
    Join Date
    01-18-2019
    Location
    Morristown, NJ
    MS-Off Ver
    Version 1812 (Build 11126.20266 Click-to-Run)
    Posts
    4

    Re: How do I flatten columns into rows?

    Quote Originally Posted by edtguy View Post
    Thanks! With a little fiddling, I was able to get to the desired state. Here are the modified formulas:

    in Sheet2!A2
    =INDEX({source sheet}!$A$2:$A${last row},IF(MOD((ROW()-1),{data rows})=0,{data rows},MOD((ROW()-1),{data rows})),1)

    in Sheet2!B2
    =INDEX({source sheet}!$B$1:${last column}!$1,1,MOD(ROW()-2,{data columns})+1)

    in Sheet2!C2
    =INDEX({source sheet}!$B$2:${last column}!${last row}!,MOD(ROW()-2,{data rows})+1,QUOTIENT(ROW()-2,{data rows})+1)

    No doubt these formulas can be refined further, and use replaceable parameters, but it works for me meeting a deadline. Thanks again!
    Whoops! I didn't review the result carefully. The location value needs to repeat over the set of categories before moving on to the next location value. The formula for column B was incorrect. Here it is corrected:

    in Sheet2!B2
    =INDEX({source sheet}!$B$1:${last column}!$1,1,TRUNC((ROW()-2)/{data columns})+1)
    Last edited by edtguy; 01-25-2019 at 04:53 PM. Reason: consistency of terms

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 03-16-2018, 05:34 PM
  2. Flatten rows into columns based on id column
    By alexjamesbrown in forum Excel General
    Replies: 10
    Last Post: 04-20-2015, 03:30 AM
  3. Flatten/ de-pivot
    By ccb81 in forum Excel General
    Replies: 1
    Last Post: 08-18-2014, 04:45 PM
  4. [SOLVED] Flatten cross table with multiple rows
    By tryndamere in forum Excel General
    Replies: 18
    Last Post: 08-16-2013, 12:40 PM
  5. Flatten a Crosstable
    By jiggaboi in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-04-2013, 03:25 PM
  6. How to 'flatten' a set of values
    By JosVL in forum Excel General
    Replies: 3
    Last Post: 12-04-2009, 04:50 AM
  7. [SOLVED] flatten pivotTable
    By [email protected] in forum Excel General
    Replies: 5
    Last Post: 01-14-2005, 06:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1