+ Reply to Thread
Results 1 to 9 of 9

Table columns to stack into pivot rows

  1. #1
    Forum Contributor
    Join Date
    02-14-2012
    Location
    Warrington
    MS-Off Ver
    Excel 365
    Posts
    377

    Table columns to stack into pivot rows

    Not sure if a pivot is the right solution here but is it possible to combine two columns of data into 1 pivot column with the variours contents showing as various rows? Simple example attached of what I'd like to achieve in the "Desired Outcome" labelled pivot from the data set on the left.
    Attached Files Attached Files

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Table columns to stack into pivot rows

    With O365, you can have an all-in-one solution. Delete all expected results.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Change the bits in red to suit.
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Table columns to stack into pivot rows

    With some conditional formatting to tart up the appearance of the table.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    02-14-2012
    Location
    Warrington
    MS-Off Ver
    Excel 365
    Posts
    377

    Re: Table columns to stack into pivot rows

    Amazing Glenn, thankyou! Only been on 365 for a short time so need to get familiar with these new functions
    Last edited by benoj2005; 03-18-2024 at 11:58 AM.

  5. #5
    Forum Contributor
    Join Date
    02-14-2012
    Location
    Warrington
    MS-Off Ver
    Excel 365
    Posts
    377

    Re: Table columns to stack into pivot rows

    Are there any easier to follow examples of solutions by the way? One that I can easily replicate. This solution is great but it's a nightmare to try and unpick and understand

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Table columns to stack into pivot rows

    The www have remarkably FEW examples of how to build these up. However, use this variant first:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Make sure there's pleanty of space around the cell with the formula. Replace the red F with any of the other sub-formula letters to see what each one returns.

    F itself is fairly self-explanatory... just bringing the individual bits together at the end.

    E is harder to understand. See how you get on with B, C and D and I'll scribble an explanation of E (as best I can).

  7. #7
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Table columns to stack into pivot rows

    MAP(INDEX(D,,1),INDEX(D,,2),INDEX(D,,3),LAMBDA(x,y,z,SUM(IF(INDEX(C,,1)=x,IF(INDEX(B,,2)=y,IF(INDEX(B,,3)=z,INDEX(B,,4),0))))))

    Normally you'd use SUMIFS to get an answer like this. But SUMIFS will not accept arrays in place of ranges. So this sort of thing is needed.

    It uses MAP in combination with LAMBDA. The main block of data after the reorganisation and stacking of columns is B.

    Change the last letter of the main formula to D. The first row looks like:

    CR 100000 12354


    Using this construction, MAP goes through each row of D, one at a time.

    MAP(CR,10000,12354,LAMBDA(x,y,z,SUM(IF(INDEX(C,,1)=x,IF(INDEX(B,,2)=y,IF(INDEX(B,,3)=z,INDEX(B,,4),0))))))

    the bits in RED are the 3 criteria for the "SUMIFS" that comes at the end. These need to be assigned names, inside LAMBDA, which does all the hard work. I called them x, y, and z.

    MAP(INDEX(D,,1),INDEX(D,,2),INDEX(D,,3),LAMBDA(x,y,z,SUM(IF(INDEX(C,,1)=x,IF(INDEX(B,,2)=y,IF(INDEX(B,,3)=z,INDEX(B,,4),0))))))


    So CR = X, 100000=Y, etc.

    MAP(INDEX(D,,1),INDEX(D,,2),INDEX(D,,3),LAMBDA(x,y,z,SUM(IF(INDEX(C,,1)=x,IF(INDEX(B,,2)=y,IF(INDEX(B,,3)=z,INDEX(B,,4),0))))))

    The bits in red (above) are the equivalent to ranges in a normal SUMIFS. So where:

    column 1 of B =x AND
    column 2 of B =y AND
    column 3 of B =z...

    it adds up the value(s) from column 4 of B. It then goes on to the next row of C, namely:

    CR 100000 12453


    and starts again. Clear as mud???

  8. #8
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    44,053

    Re: Table columns to stack into pivot rows

    FWIW, I learned how to do these things by mucking around with problems like yours. Two years ago, I hadn't a clue how they worked... and I'm still not nearly as good as some others here in applying them. But, I can get them to work (at least some of the time...).

  9. #9
    Forum Contributor
    Join Date
    02-14-2012
    Location
    Warrington
    MS-Off Ver
    Excel 365
    Posts
    377

    Re: Table columns to stack into pivot rows

    Thanks for explaining it Glenn. I probably need to look into the functions I dont recognise like MAP, LAMBA & LET and get my head around each one individually to be able to understand the bigger picture better as like you say, it's "clear as mud" right now

+ 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. [SOLVED] Get values from varying rows and columns of Pivot Table and enter those in different table
    By Richavlaues in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-25-2016, 10:24 AM
  2. Stack Tabulated (Pivot Table) Data Sheet
    By mrruz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2014, 12:04 PM
  3. Replies: 1
    Last Post: 11-29-2012, 06:24 PM
  4. stack filters in pivot table
    By imatomic in forum Excel General
    Replies: 0
    Last Post: 05-17-2010, 07:08 PM
  5. Replies: 1
    Last Post: 04-09-2010, 08:58 PM
  6. Too many rows or columns in my pivot-table
    By markus in forum Excel General
    Replies: 1
    Last Post: 08-14-2006, 10:00 AM
  7. Pivot Table - too many rows/columns error
    By bill_morgan in forum Excel General
    Replies: 1
    Last Post: 02-02-2006, 02:00 AM

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